Teamspeak3 - Plugin pour Among Us

Partagez vos scripts, et vos applications AutoIt.
Règles du forum
.
Répondre
dragonsayen
Niveau 1
Niveau 1
Messages : 1
Enregistré le : jeu. 12 nov. 2020 17:59
Status : Hors ligne

Teamspeak3 - Plugin pour Among Us

#1

Message par dragonsayen »

Hello,

Pour gérer TeamSpeak3 pour le jeu Among Us j'ai créé un petit plugin utilisant l'API TeamSpeak.

Je me suis dit que ça pourrait intéresser d'autres personnes, donc voilà le code. ( il y a aussi des images, vous pouvez aller sur https://dragonsayen.com/ts3_amongus_plugin/ récupérer le zip avec la source et les images ).

Preneur si vous avez des retours, des idées ou si vous avez des bugs.
; Created by Dragonsayen (dragonsayen@dragonsayen.com)
#pragma compile(Out, TS3-Among_Us.exe)
#pragma compile(ExecLevel, none)
;#pragma compile(Compatibility, win8)
#pragma compile(UPX, False)
#pragma compile(FileDescription, TeamSpeak3 plugin for Among Us Game)
#pragma compile(ProductName, TS3-Among_Us)
#pragma compile(ProductVersion, 0.2)
#pragma compile(FileVersion, 0.2.0)
#pragma compile(CompanyName, 'Dragonsayen')
#pragma compile(Compression, 5)
#pragma compile(x64, true)

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <ColorConstants.au3>
_Singleton ( "AmongUs_TS3Plugin_By_Dragonsayen" )

; Install the required images
if Not FileExists(@ScriptDir & "/images") or not FileExists(@ScriptDir & "/README.txt") Then
   DirCreate ( @ScriptDir & "/images" )
   FileInstall("README.txt", @ScriptDir & "/README.txt")
   FileInstall("images/AmongUs.jpg", @ScriptDir & "/images/AmongUs.jpg")
   FileInstall("images/AdminButton.jpg", @ScriptDir & "/images/AdminButton.jpg")
   FileInstall("images/Discuss.bmp", @ScriptDir & "/images/Discuss.bmp")
   FileInstall("images/shhhhh.bmp", @ScriptDir & "/images/shhhhh.bmp")
   FileInstall("images/Vitals.bmp", @ScriptDir & "/images/Vitals.bmp")
   FileInstall("images/Start.bmp", @ScriptDir & "/images/Start.bmp")
   FileInstall("images/Black.bmp", @ScriptDir & "/images/Black.bmp")
   FileInstall("images/BlackDead.bmp", @ScriptDir & "/images/BlackDead.bmp")
   FileInstall("images/Blue.bmp", @ScriptDir & "/images/Blue.bmp")
   FileInstall("images/BlueDead.bmp", @ScriptDir & "/images/BlueDead.bmp")
   FileInstall("images/Brown.bmp", @ScriptDir & "/images/Brown.bmp")
   FileInstall("images/BrownDead.bmp", @ScriptDir & "/images/BrownDead.bmp")
   FileInstall("images/Cyan.bmp", @ScriptDir & "/images/Cyan.bmp")
   FileInstall("images/CyanDead.bmp", @ScriptDir & "/images/CyanDead.bmp")
   FileInstall("images/Green.bmp", @ScriptDir & "/images/Green.bmp")
   FileInstall("images/GreenDead.bmp", @ScriptDir & "/images/GreenDead.bmp")
   FileInstall("images/Lime.bmp", @ScriptDir & "/images/Lime.bmp")
   FileInstall("images/LimeDead.bmp", @ScriptDir & "/images/LimeDead.bmp")
   FileInstall("images/Orange.bmp", @ScriptDir & "/images/Orange.bmp")
   FileInstall("images/OrangeDead.bmp", @ScriptDir & "/images/OrangeDead.bmp")
   FileInstall("images/Pink.bmp", @ScriptDir & "/images/Pink.bmp")
   FileInstall("images/PinkDead.bmp", @ScriptDir & "/images/PinkDead.bmp")
   FileInstall("images/Purple.bmp", @ScriptDir & "/images/Purple.bmp")
   FileInstall("images/PurpleDead.bmp", @ScriptDir & "/images/PurpleDead.bmp")
   FileInstall("images/Red.bmp", @ScriptDir & "/images/Red.bmp")
   FileInstall("images/RedDead.bmp", @ScriptDir & "/images/RedDead.bmp")
   FileInstall("images/White.bmp", @ScriptDir & "/images/White.bmp")
   FileInstall("images/WhiteDead.bmp", @ScriptDir & "/images/WhiteDead.bmp")
   FileInstall("images/Yellow.bmp", @ScriptDir & "/images/Yellow.bmp")
   FileInstall("images/YellowDead.bmp", @ScriptDir & "/images/YellowDead.bmp")
EndIf

$version="0.2"
$onlineVersion = BinaryToString (InetRead ("http://dragonsayen.com/ts3_amongus_plugin/version", 1))
if $onlineVersion <> $version AND StringLen($onlineVersion) > 2 AND StringLen($onlineVersion) < 5 then
   MsgBox(0, "New version !", "A new version (old : "&$version&", new : "&$onlineVersion&") of this tool is available at https://dragonsayen.com/ts3_amongus_plugin" & @CRLF & @CRLF & "To update, download the new .exe file, and remove everything from the old version except the .ini file.")
endif

; Read the config.ini file, or set default values if not founded
$host = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "host", "0.0.0.0")
$port = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "port", 0)
$apikey = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "apikey", "XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX")
$ts3ChannelAmongUs = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "channel_amongus_cid", 0)
$ts3ChannelDead = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "channel_dead_cid", 0)
$ts3GroupAlive = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "group_alive_cgid", 0)
$ts3GroupDead = IniRead( @ScriptDir & "/config.ini", "ts3_telnet_config", "group_dead_cgid", 0)

; If nothing is loaded from the config.ini file, ask for the information to the user and save them to the ini file
If $host == "0.0.0.0" then
   $host = InputBox ( "Among Us - TS3 Plugin", "Enter the hostname for the TS3 client you want to connect to (usually : 127.0.0.1)", "127.0.0.1" )
   IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "host", $host)
EndIf
If $port == 0 then
   $port = InputBox ( "Among Us - TS3 Plugin", "Enter the port number for the client you want to connect to (usually : 25639)", "25639" )
   IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "port", $port)
EndIf
If $apikey == "XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX" then
   $apikey = InputBox ( "Among Us - TS3 Plugin", "Enter your API KEY (For TS3 client version 3.5.3 : Go to Tools -> Options -> Addons -> ClientQuery -> Settings)", "XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX" )
   IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "apikey", $apikey)
EndIF

;GUI Creation
GuiCreate("Among Us - TS3 Plugin", 500, 1000,-1, -1 )
GUICtrlCreatePic ( @ScriptDir & "/images/AmongUs.jpg", 125, 10, 250, 68 )
GUICtrlCreateLabel ( "DEBUG - Input your own commands to your TeamSpeak3 Client", 110, 720 )
GUICtrlCreatePic ( @ScriptDir & "/images/AdminButton.jpg", 10, 690, 60, 60 )
$debugResult = GuiCtrlCreateEdit("", 10, 750, 480, 200)
GUICtrlSetData ( $debugResult, "Created by Dragonsayen (https://dragonsayen.com/ts3_amongus_plugin) (version : "&$version&")" )
$debugInput = GuiCtrlCreateInput("", 10, 970, 480, 20)
GUICtrlSetState($debugInput, $GUI_DISABLE)
$connectedLabel = GUICtrlCreateLabel ( "Not connected to your TeamSpeak3 Client ...", 10, 80, 980 )
GUICtrlSetColor($connectedLabel, $COLOR_RED)
$channelAmongUsLabel = GUICtrlCreateLabel ( "Invalid Among Us Channel ID : " & $ts3ChannelAmongUs, 10, 95, 980 )
GUICtrlSetColor($channelAmongUsLabel, $COLOR_RED)
$channelDeadLabel = GUICtrlCreateLabel ( "Invalid Dead Channel ID : " & $ts3ChannelDead, 10, 110, 980 )
GUICtrlSetColor($channelDeadLabel, $COLOR_RED)
$groupAliveLabel = GUICtrlCreateLabel ( "Invalid Alive Group Channel ID : " & $ts3GroupAlive, 10, 125, 980 )
GUICtrlSetColor($groupAliveLabel, $COLOR_RED)
$groupDeadLabel = GUICtrlCreateLabel ( "Invalid Dead Group Channel ID : " & $ts3GroupDead, 10, 140, 980 )
GUICtrlSetColor($groupDeadLabel, $COLOR_RED)
$shhButton = GUICtrlCreateButton ( "Shhhhh", 25, 155, 105, 105, $BS_BITMAP )
GUICtrlSetImage ( $shhButton, @ScriptDir & "/images/shhhhh.bmp" )
GUICtrlSetTip ( $shhButton, "Move dead players to the Dead channel and change the channel permission to disallow Alive group to speak." )
$discussButton = GUICtrlCreateButton ( "Discuss", 135, 155, 105, 105, $BS_BITMAP )
GUICtrlSetImage ( $discussButton, @ScriptDir & "/images/Discuss.bmp" )
GUICtrlSetTip ( $discussButton, "Move all players to the Among Us channel and change the channel permission to allow Alive group to speak." )
$refreshButton = GUICtrlCreateButton ( "Refresh", 280, 155, 105, 105, $BS_BITMAP )
GUICtrlSetImage ( $refreshButton, @ScriptDir & "/images/Vitals.bmp" )
GUICtrlSetTip ( $refreshButton, "Refresh the list and status of all players." )
$startButton = GUICtrlCreateButton ( "Refresh", 390, 180, 95, 55, $BS_BITMAP )
GUICtrlSetImage ( $startButton, @ScriptDir & "/images/Start.bmp" )
GUICtrlSetTip ( $startButton, "Reset all players to alive, all back to the main channel." )
$maxNbPlayers = 12
Dim $playerImages[$maxNbPlayers+1]
Dim $playerNames[$maxNbPlayers+1]
Dim $playerColors[$maxNbPlayers+1]
Dim $playerStatus[$maxNbPlayers+1]
For $i = 1 to $maxNbPlayers
   if ($i/2)=Round($i/2) then
      $newX = 260
      $newY = 200 + (($i/2) * 70)
   else
      $newX = 10
      $newY = 200 + (Ceiling($i/2) * 70)
   endif
   $playerImages[$i] = GUICtrlCreateButton ("Player"&$i, $newX, $newY, 50, 65, $BS_BITMAP )
   GUICtrlSetImage ( $playerImages[$i], @ScriptDir & "/images/Red.bmp" )
   $playerNames[$i] = GUICtrlCreateLabel ("Pseudo Player "&$i, $newX+60, $newY+10, 180 )
   $playerStatus[$i] = GUICtrlCreateLabel ("Status : Unknown", $newX+60, $newY+25, 180 )
   $playerColors[$i] = GUICtrlCreateCombo("", $newX+60, $newY+40, 100)
   GUICtrlSetData(-1, "Black|Blue|Brown|Cyan|Green|Lime|Orange|Pink|Purple|Red|White|Yellow", "Red")
Next
hideAllPlayers()
GUISetState ()

; Start the TCP connection
TCPStartup ()
$TCPHost = TCPNameToIP ( $host )

; Init the TCP Connection
$connection = TCPConnect ( $TCPHost, $port )
If @error Then
   MsgBox(16, "Among Us - TS3 Plugin - Error connection", "Impossible to connect to TS3 client using telnet. Please verify or delete the config.ini file and restart the program", 60 )
   Exit
EndIf

; Put some limits
$maxChannels = 255
$maxChannelGroups = 255
; Limit to the first 12 people in the channel (it should be ok with 10 is the maximum amount of players in Among Us)
$maxPlayers = 12

$connectedToTS3Client = False
$authenticatedToTS3Client = False
$channelDeadOk = False
$channelAmongUsOk = False
$groupAliveOk = False
$groupDeadOk = False
$myClID = 0
$lastCommand = ""
$cmdAuth = "auth apikey=" & $apikey
$cmdChannelList = "channellist"
$cmdChannelGroupList1 = "clientnotifyregister schandlerid=1 event=notifychannelgrouplist"
$cmdChannelGroupList2 = "channelgrouplist"
$cmdClientList = "clientlist -groups"
$cmdMuteMyself = "clientupdate client_input_muted=1"
$cmdUnmuteMyself = "clientupdate client_input_muted=0"
$cmdWhoAmI = "whoami"
Dim $channels[$maxChannels][2]
$channels[0][0] = 0
Dim $channelGroups[$maxChannelGroups][2]
$channelGroups[0][0] = 0
; Get the name, the color, the status (alive/dead/unknown), the channel (amongus/dead), the clid (clientid), the clbdig (id in bdd). Order by clid.
Dim $players[$maxPlayers+1][6]
$nbPlayers = 0
; Automatically refresh the interface every 60000 ms ( 1 min )
;AdlibRegister ( "refresh", 60000 )

While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
   $received = TCPRecv ( $connection, 2048 )
   If $received <> "" Then
      $text = GUICtrlRead ( $debugResult )
      GUICtrlSetData ( $debugResult,$text & @CRLF & $received )
      ; Check if the message is a success connection to TS3 client
      If StringInStr($received, "Welcome to the TeamSpeak 3 ClientQuery interface") Then
         $connectedToTS3Client = True
         GUICtrlSetData ( $connectedLabel, "Successfully connected to your TeamSpeak3 Client" )
         GUICtrlSetColor($connectedLabel, $COLOR_YELLOW)
         ; Authenticate using the API KEY
         TCPSend ( $connection, $cmdAuth & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdAuth )
         $lastCommand = $cmdAuth
      ; Check if the authentication with the APIKEY is a success
      ElseIf StringInStr($lastCommand, "auth apikey=") AND StringInStr($received, "error id=0 msg=ok") Then
         $authenticatedToTS3Client = True
         GUICtrlSetData ($connectedLabel, "Successfully connected to your TeamSpeak3 Client with API KEY !" )
         GUICtrlSetColor($connectedLabel, $COLOR_GREEN)
         ; try to list all channels of the TS3 to verify the channel Among Us and the channel for the dead
         TCPSend ( $connection, $cmdChannelList & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdChannelList )
         $lastCommand = $cmdChannelList
      ; In case the authentication with the APIKEY failed, enable the debug command input
      ElseIf $lastCommand = $cmdAuth Then
         $authenticatedToTS3Client = False
         GUICtrlSetState($debugInput, $GUI_ENABLE)
         MsgBox(16, "Error !", "Cannot connect to your TS3 Client with your API KEY ! Please verify your apikey (config.ini file) or try to authenticate using the Debug console at the bottom", 60)
      ; In case the previous command was about updating a player status
      ElseIf StringInStr($lastCommand, "setclientchannelgroup cgid=") AND StringInStr($received, "error id=0 msg=ok") Then
         ; Refresh client list
         TCPSend ( $connection, $cmdClientList & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdClientList )
         $lastCommand = $cmdClientList
      ; Store the channels into an array. It's mainly used to verify if both channel Among Us and channel for the dead are well defined
      ElseIf $lastCommand = $cmdChannelList Then
         $splitChannels = StringSplit($received, "|")
         Dim $channels[255][2]
         $channels[0][0] = 0
         $dispChannels = ""
         For $i = 1 To $splitChannels[0]
            $cidPos = StringInStr($splitChannels[$i], "cid=")
            if $cidPos > 0 then
               $subCid = StringTrimLeft($splitChannels[$i], $cidPos + 3)
               $splitCid = StringSplit($subCid, " |")
               $channels[$i][0] = $splitCid[1]
               $dispChannels &= "cid=" & $splitCid[1] & " | "
               $channels[0][0] += 1
               $cnamePos = StringInStr($splitChannels[$i], "channel_name=")
               if $cnamePos > 0 Then
                  $subCname = StringTrimLeft($splitChannels[$i], $cnamePos + 12)
                  $splitCname = StringSplit($subCname, " |")
                  $cname = StringReplace($splitCname[1], "\s", " ")
                  $channels[$i][1] = $cname
                  $dispChannels &= $cname & @CRLF
               EndIf
            EndIf
         Next
         ReDim $channels[$channels[0][0]+1][2]
         ; Verify if the cid of the channel AmongUs and the cid of the channel for the dead are OK
         $channelNameAmongUs = ""
         $channelNameDead = ""
         While Not $channelAmongUsOk Or Not $channelDeadOk
            For $i = 1 To $channels[0][0]
               if $channels[$i][0] == $ts3ChannelAmongUs then
                  $channelAmongUsOk = True
                  $channelNameAmongUs = $channels[$i][1]
               elseif $channels[$i][0] == $ts3ChannelDead then
                  $channelDeadOk = True
                  $channelNameDead = $channels[$i][1]
               endif
            Next
            If not $channelAmongUsOk Then
               $ts3ChannelAmongUs = InputBox("Select the AmongUs Channel", "AMONG US CHANNEL" & @CRLF & "It looks like the channel with cid=" & $ts3ChannelAmongUs & " does not exist. Please create an Among Us channel in your Teamspeak Server or select one below by entering the correct cid."&@CRLF&"Ensure that in this channel, the dead have not enough talk power by setting the Needed Client Talk Power to 5 for the channel, the client talk power to 10 for the Alive channel group, and the client talk power to 1 for the Dead channel group. Finally, check the Sticky client for the Alive channel group so that they can't move to the dead channel." & @CRLF & @CRLF & $dispChannels, $ts3ChannelAmongUs, "", 400, 900)
               if @Error == 1 Then
                  ExitLoop
               EndIf
               IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "channel_amongus_cid", $ts3ChannelAmongUs)
            EndIf
            If not $channelDeadOk Then
               $ts3ChannelDead = InputBox("Select the Dead Channel", "DEAD CHANNEL" & @CRLF & "It looks like the channel with cid=" & $ts3ChannelDead & " does not exist. Please create a channel for the dead in your Teamspeak Server or select one below by entering the correct cid."&@CRLF&"Ensure that in this channel, the dead have enough talk power and enough join power to move around freely between the Among Us channel and the dead channel. Finally, check the Sticky client for the Alive channel group so that they can't move to the dead channel. Also you can disallow Send Text Messages permissions for everyone if you want to." & @CRLF & @CRLF & $dispChannels, $ts3ChannelDead, "", 400, 900)
               if @Error == 1 Then
                  ExitLoop
               EndIf
               IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "channel_dead_cid", $ts3ChannelDead)
            EndIf
         WEnd
         if $channelAmongUsOk Then
            GUICtrlSetData ($channelAmongUsLabel, "Channel Among Us : " & $channelNameAmongUs & "(" & $ts3ChannelAmongUs & ")" )
            GUICtrlSetColor($channelAmongUsLabel, $COLOR_GREEN)
         EndIf
         if $channelDeadOk Then
            GUICtrlSetData ($channelDeadLabel, "Channel for Dead : " & $channelNameDead & "(" & $ts3ChannelDead & ")" )
            GUICtrlSetColor($channelDeadLabel, $COLOR_GREEN)
         EndIf
         ; Now try to verify channel groups. Start with adding the listener
         TCPSend ( $connection, $cmdChannelGroupList1 & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdChannelGroupList1 )
         $lastCommand = $cmdChannelGroupList1
      ElseIf $lastCommand = $cmdChannelGroupList1 AND StringInStr($received, "error id=0 msg=ok") Then
         ; Now try to verify channel groups
         TCPSend ( $connection, $cmdChannelGroupList2 & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdChannelGroupList2 )
         $lastCommand = $cmdChannelGroupList2
      ElseIf $lastCommand = $cmdChannelGroupList2 Then
         $splitGroups = StringSplit($received, "|")
         Dim $channelGroups[255][2]
         $channelGroups[0][0] = 0
         $dispGroups = ""
         For $i = 1 To $splitGroups[0]
            $cgidPos = StringInStr($splitGroups[$i], "cgid=")
            if $cgidPos > 0 then
               $subCgid = StringTrimLeft($splitGroups[$i], $cgidPos + 4)
               $splitCgid = StringSplit($subCgid, " |")
               $channelGroups[$i][0] = $splitCgid[1]
               $dispGroups &= "cgid=" & $splitCgid[1] & " | "
               $channelGroups[0][0] += 1
               $namePos = StringInStr($splitGroups[$i], "name=")
               if $namePos > 0 Then
                  $subName = StringTrimLeft($splitGroups[$i], $namePos + 4)
                  $splitName = StringSplit($subName, " |")
                  $name = StringReplace($splitName[1], "\s", " ")
                  $channelGroups[$i][1] = $name
                  $dispGroups &= $name & @CRLF
               EndIf
            EndIf
         Next
         ReDim $channelGroups[$channelGroups[0][0]+1][2]
         ; Verify if the cid of the channel AmongUs and the cid of the channel for the dead are OK
         $groupNameAlive = ""
         $groupNameDead = ""
         While Not $groupAliveOk Or Not $groupDeadOk
            For $i = 1 To $channelGroups[0][0]
               if $channelGroups[$i][0] == $ts3GroupAlive then
                  $groupAliveOk = True
                  $groupNameAlive = $channelGroups[$i][1]
               elseif $channelGroups[$i][0] == $ts3GroupDead then
                  $groupDeadOk = True
                  $groupNameDead = $channelGroups[$i][1]
               endif
            Next
            If not $groupAliveOk Then
               $ts3GroupAlive = InputBox("Select the Alive Group Channel", "ALIVE GROUP" & @CRLF & "It looks like the group channel with cgid=" & $ts3GroupAlive & " does not exist. Please select the right one from the list below by inputting the correct cgid." & @CRLF & @CRLF & $dispGroups, $ts3GroupAlive, "", 400, 900)
               if @Error == 1 Then
                  ExitLoop
               EndIf
               IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "group_alive_cgid", $ts3GroupAlive)
            EndIf
            If not $groupDeadOk Then
               $ts3GroupDead = InputBox("Select the Dead Group Channel", "DEAD GROUP" & @CRLF & "It looks like the group channel with cgid=" & $ts3GroupDead & " does not exist. Please select the right one from the list below by inputting the correct cgid." & @CRLF & @CRLF & $dispGroups, $ts3GroupDead, "", 400, 900)
               if @Error == 1 Then
                  ExitLoop
               EndIf
               IniWrite(@ScriptDir & "/config.ini", "ts3_telnet_config", "group_dead_cgid", $ts3GroupDead)
            EndIf
         WEnd
         ; Enable the input now everything is ok
         GUICtrlSetState($debugInput, $GUI_ENABLE)
         if $groupAliveOk Then
            GUICtrlSetData ($groupAliveLabel, "Group for Alive players : " & $groupNameAlive & "(" & $ts3GroupAlive & ")" )
            GUICtrlSetColor($groupAliveLabel, $COLOR_GREEN)
         EndIf
         if $groupDeadOk Then
            GUICtrlSetData ($groupDeadLabel, "Group for Dead players : " & $groupNameDead & "(" & $ts3GroupDead & ")" )
            GUICtrlSetColor($groupDeadLabel, $COLOR_GREEN)
         EndIf
         ; Now try to get whoami clientid
         TCPSend ( $connection, $cmdWhoAmI & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdWhoAmI )
         $lastCommand = $cmdWhoAmI
      ElseIf $lastCommand = $cmdClientList Then
         $splitClients = StringSplit($received, "|")
         Dim $newPlayersList[$maxPlayers+1][6]
         $newNbPlayers = 0
         ; 0 : clid, 1 : name, 2 : status, 3 : channel, 4 : color, 5 : clbdid
         For $i = 1 To $splitClients[0]
            $channelPos = StringInStr($splitClients[$i], "cid=")
            if $channelPos > 0 then
               $subChannel = StringTrimLeft($splitClients[$i], $channelPos + 3)
               $splitChannel = StringSplit($subChannel, " |e")
               if $splitChannel[1] == $ts3ChannelAmongUs OR $splitChannel[1] == $ts3ChannelDead then
                  $newNbPlayers += 1
                  if $splitChannel[1] == $ts3ChannelAmongUs then
                     $newPlayersList[$newNbPlayers][3] = "amongus"
                  else
                     $newPlayersList[$newNbPlayers][3] = "dead"
                  endif
                  $clidPos = StringInStr($splitClients[$i], "clid=")
                  if $clidPos > 0 then
                     $subClid = StringTrimLeft($splitClients[$i], $clidPos + 4)
                     $splitClid = StringSplit($subClid, " |e")
                     $newPlayersList[$newNbPlayers][0] = $splitClid[1]
                     $namePos = StringInStr($splitClients[$i], "client_nickname=")
                     if $namePos > 0 then
                        $subName = StringTrimLeft($splitClients[$i], $namePos + 15)
                        $splitName = StringSplit($subName, " |")
                        $newPlayersList[$newNbPlayers][1] = StringReplace($splitName[1], "\s", " ")
                     endif
                     $groupPos = StringInStr($splitClients[$i], "client_channel_group_id=")
                     if $groupPos > 0 then
                        $subGroup = StringTrimLeft($splitClients[$i], $groupPos + 23)
                        $splitGroup = StringSplit($subGroup, " |e")
                        $groupPlayer = StringStripWS($splitGroup[1], 8)
                        if $groupPlayer == $ts3GroupAlive then
                           $newPlayersList[$newNbPlayers][2] = "Alive"
                        elseif $groupPlayer == $ts3GroupDead then
                           $newPlayersList[$newNbPlayers][2] = "Dead"
                        else
                           $newPlayersList[$newNbPlayers][2] = "Unknown"
                        endif
                     endif
                     $clbdigPos = StringInStr($splitClients[$i], "client_database_id=")
                     if $clbdigPos > 0 then
                        $subClbdid = StringTrimLeft($splitClients[$i], $clbdigPos + 18)
                        $splitClbdid = StringSplit($subClbdid, " |e")
                        $newPlayersList[$newNbPlayers][5] = $splitClbdid[1]
                     endif
                     $newPlayersList[$newNbPlayers][4] = "Red"
                     for $j = 1 To $nbPlayers
                        if $players[$j][0] = $newPlayersList[$newNbPlayers][0] then
                           $newPlayersList[$newNbPlayers][4] = $players[$j][4]
                        endif
                     next
                  endif
               endif
            endif
         Next
         ReDim $newPlayersList[$newNbPlayers+1][6]
         _ArraySort($newPlayersList)
         $nbPlayers = $newNbPlayers
         $players = $newPlayersList
         refreshUIPlayers($players)
      ElseIf $lastCommand == $cmdWhoAmI Then
         $myClidPos = StringInStr($received, "clid=")
         if $myClidPos > 0 Then
            $subMyClid = StringTrimLeft($received, $myClidPos + 4)
            $splitMyClid = StringSplit($subMyClid, " |e")
            $myClID = $splitMyClid[1]
            GUICtrlSetData ($connectedLabel, "Successfully connected to TeamSpeak3 Client with API KEY ! Your clid : "&$myClID )
         EndIf
         ; Now try to get the list of client in the AmongUs Channel (and dead channel)
         TCPSend ( $connection, $cmdClientList & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdClientList )
         $lastCommand = $cmdClientList
      EndIf
   EndIf
   
   ; When modifying a color, save it and refresh UI for players
   for $i = 1 to $maxNbPlayers
      if $msg == $playerColors[$i] then
         $newColor = GUICtrlRead ( $playerColors[$i] )
         $players[$i][4] = $newColor
         refreshUIPlayers($players)
      endif
   Next
   
   For $i=1 to $maxNbPlayers
      if $msg == $playerImages[$i] then
         $channelToUse = $ts3ChannelAmongUs
         if $players[$i][3] == "dead" then
            $channelToUse = $ts3ChannelDead
         endif
         if $players[$i][2] == "Alive" Then
            $cmdUpdatePlayer = "setclientchannelgroup cgid=" & $ts3GroupDead & " cid=" & $channelToUse & " cldbid=" & $players[$i][5]
            $players[$i][2] = "Dead"
         else
            $cmdUpdatePlayer = "setclientchannelgroup cgid=" & $ts3GroupAlive & " cid=" & $channelToUse & " cldbid=" & $players[$i][5]
            $players[$i][2] = "Alive"
         endif
         TCPSend ( $connection, $cmdUpdatePlayer & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdUpdatePlayer )
         $lastCommand = $cmdUpdatePlayer
      endif
   Next
   
   ; When clicking the shhh button, move dead players to the dead canal, and change canal talk permission
   if $msg == $shhButton then
      $listOfDeads = ""
      for $i = 0 To $nbPlayers
         if $players[$i][2] == "Dead" AND $players[$i][3] == "amongus" then
            $listOfDeads &= "clid="&$players[$i][0]&"|"
            $players[$i][3] = "dead"
         endif
         if $players[$i][0] == $myClID AND $myClID > 0 Then
            if $players[$i][2] == "Dead" Then
               $cmdForMySelf = $cmdUnmuteMyself
            Else
               $cmdForMySelf = $cmdMuteMyself
            EndIf
            ; Now try to mute or unmute myself
            TCPSend ( $connection, $cmdForMySelf & @LF )
            $text = GUICtrlRead ( $debugResult )
            GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdForMySelf )
            $lastCommand = $cmdForMySelf
         EndIf
      next
      if $listOfDeads <> "" then
         $listOfDeadToMove = StringTrimRight($listOfDeads,1)
         $moveCommand = "clientmove cid=" & $ts3ChannelDead & " " & $listOfDeadToMove
         ; Now try to move the dead to the dead channel
         TCPSend ( $connection, $moveCommand & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $moveCommand )
         $lastCommand = $moveCommand
      endif
      ;now edit the channel permission of AmongUs
      $commandPermissionToDiscuss = "channeladdperm cid="&$ts3ChannelAmongUs&" permsid=i_client_needed_talk_power permvalue=15"
      TCPSend ( $connection, $commandPermissionToDiscuss & @LF )
      $text = GUICtrlRead ( $debugResult )
      GUICtrlSetData ( $debugResult,$text & @CRLF & $commandPermissionToDiscuss )
      $lastCommand = $commandPermissionToDiscuss
   elseif $msg == $discussButton then
      $listOfDeads = ""
      for $i = 0 To $nbPlayers
         if $players[$i][2] == "Dead" AND $players[$i][3] == "dead" then
            $listOfDeads &= "clid="&$players[$i][0]&"|"
            $players[$i][3] = "amongus"
         endif
         if $players[$i][0] == $myClID AND $myClID > 0 Then
            if $players[$i][2] == "Dead" Then
               $cmdForMySelf = $cmdMuteMyself
            Else
               $cmdForMySelf = $cmdUnmuteMyself
            EndIf
            ; Now try to mute or unmute myself
            TCPSend ( $connection, $cmdForMySelf & @LF )
            $text = GUICtrlRead ( $debugResult )
            GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdForMySelf )
            $lastCommand = $cmdForMySelf
         EndIf
      next
      if $listOfDeads <> "" then
         $listOfDeadToMove = StringTrimRight($listOfDeads,1)
         $moveCommand = "clientmove cid=" & $ts3ChannelAmongUs & " " & $listOfDeadToMove
         ; Now try to move the dead to the Among Us channel
         TCPSend ( $connection, $moveCommand & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $moveCommand )
         $lastCommand = $moveCommand
      endif
      ;now edit the channel permission of AmongUs
      $commandPermissionToDiscuss = "channeladdperm cid="&$ts3ChannelAmongUs&" permsid=i_client_needed_talk_power permvalue=5"
      TCPSend ( $connection, $commandPermissionToDiscuss & @LF )
      $text = GUICtrlRead ( $debugResult )
      GUICtrlSetData ( $debugResult,$text & @CRLF & $commandPermissionToDiscuss )
      $lastCommand = $commandPermissionToDiscuss
   elseif $msg == $refreshButton then
      refresh()
   elseif $msg == $startButton then
      ; Now try to unmute myself
      TCPSend ( $connection, $cmdUnmuteMyself & @LF )
      $text = GUICtrlRead ( $debugResult )
      GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdUnmuteMyself )
      $lastCommand = $cmdUnmuteMyself
      $listOfDeads = ""
      for $i = 0 To $nbPlayers
         if $players[$i][2] == "Dead" AND $players[$i][3] == "dead" then
            $listOfDeads &= "clid="&$players[$i][0]&"|"
            $players[$i][3] = "amongus"
         endif
      next
      if $listOfDeads <> "" then
         $listOfDeadToMove = StringTrimRight($listOfDeads,1)
         $moveCommand = "clientmove cid=" & $ts3ChannelAmongUs & " " & $listOfDeadToMove
         ; Now try to move the dead to the Among Us channel
         TCPSend ( $connection, $moveCommand & @LF )
         $text = GUICtrlRead ( $debugResult )
         GUICtrlSetData ( $debugResult,$text & @CRLF & $moveCommand )
         $lastCommand = $moveCommand
      endif
      for $i = 0 To $nbPlayers
         if $players[$i][2] == "Dead" then
            $cmdUpdatePlayer = "setclientchannelgroup cgid=" & $ts3GroupAlive & " cid=" & $ts3ChannelAmongUs & " cldbid=" & $players[$i][5]
            TCPSend ( $connection, $cmdUpdatePlayer & @LF )
            $text = GUICtrlRead ( $debugResult )
            GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdUpdatePlayer )
            $lastCommand = $cmdUpdatePlayer
            $players[$i][2] = "Alive"
         endif
      next
      refreshUIPlayers($players)
      ;now edit the channel permission of AmongUs
      $commandPermissionToDiscuss = "channeladdperm cid="&$ts3ChannelAmongUs&" permsid=i_client_needed_talk_power permvalue=5"
      TCPSend ( $connection, $commandPermissionToDiscuss & @LF )
      $text = GUICtrlRead ( $debugResult )
      GUICtrlSetData ( $debugResult,$text & @CRLF & $commandPermissionToDiscuss )
      $lastCommand = $commandPermissionToDiscuss
   endif

   ; When an input is done using the debug part
   If $msg = $debugInput Then
      $text = GUICtrlRead ( $debugResult )
      $sendTCP = GUICtrlRead ( $debugInput )
      GUICtrlSetData ( $debugResult, $text & @CRLF & $sendTCP )
      GUICtrlSetData ( $debugInput, "" )
      $lastCommand = $sendTCP
      TCPSend ( $connection, $sendTCP & @LF )
      If @error Then
         MsgBox (16,"Error TCP","Error while sending the TCP message", 60)
         Exit
      EndIf
   EndIf
WEnd
Exit

Func refresh()
   ; Refresh client list
   TCPSend ( $connection, $cmdClientList & @LF )
   $text = GUICtrlRead ( $debugResult )
   GUICtrlSetData ( $debugResult,$text & @CRLF & $cmdClientList )
   $lastCommand = $cmdClientList
EndFunc

Func refreshUIPlayers($arrayPlayers)
   hideAllPlayers()
   $currentNbPlayers = UBound($arrayPlayers)-1
   for $i = 1 to $currentNbPlayers
      if $arrayPlayers[$i][2] == "Dead" then
         GUICtrlSetImage ($playerImages[$i], @ScriptDir & "/images/"&$arrayPlayers[$i][4]&"Dead.bmp" )
         GUICtrlSetColor($playerStatus[$i], $COLOR_RED)
      else
         GUICtrlSetImage ($playerImages[$i], @ScriptDir & "/images/"&$arrayPlayers[$i][4]&".bmp" )
         if $arrayPlayers[$i][2] == "Alive" then
            GUICtrlSetColor($playerStatus[$i], $COLOR_GREEN)
         else
            GUICtrlSetColor($playerStatus[$i], $COLOR_YELLOW)
         endif
      endif
      GUICtrlSetData ($playerStatus[$i], "Status : " & $arrayPlayers[$i][2] )
      GUICtrlSetData ($playerNames[$i], $arrayPlayers[$i][1] )
      GUICtrlSetData ($playerColors[$i], $arrayPlayers[$i][4] )
   next
   displayNbPlayers($currentNbPlayers)
EndFunc

Func displayNbPlayers($nbPlayers)
   ; This function will hide or display the right numbers of players.
   For $i=1 to $nbPlayers
      GUICtrlSetState ($playerImages[$i], $GUI_SHOW)
      GUICtrlSetState ($playerNames[$i], $GUI_SHOW)
      GUICtrlSetState ($playerStatus[$i], $GUI_SHOW)
      GUICtrlSetState ($playerColors[$i], $GUI_SHOW)
   Next
EndFunc

Func hideAllPlayers()
   For $i=1 To $maxNbPlayers
      GUICtrlSetState ($playerImages[$i], $GUI_HIDE)
      GUICtrlSetState ($playerNames[$i], $GUI_HIDE)
      GUICtrlSetState ($playerStatus[$i], $GUI_HIDE)
      GUICtrlSetState ($playerColors[$i], $GUI_HIDE)
   Next
EndFunc
Répondre