Author | Message | Time |
---|---|---|
Strilanc | I've almost finished writing a bot which can host games in wc3. The last obstacle comes at the very end: when players finish loading and enter the map. The bots responsibilities end there, and so I want it to exit graciously. The problem is all the strategies I've tried for disconnecting end up killing the game (players are sent straight to the score screen). My fear is that I will need to send something different for every map. Does anyone have any experience with this? [code] Public Function startCountdown() As Boolean broadcastPacket(GID.START_COUNTDOWN, array(Of Byte)()) For i As Integer = 5 To 1 Step -1 say("Game starting in " + i.ToString(), Color.Red) Threading.Thread.Sleep(1000) Next i say("Starting Game", Color.Red) broadcastPacket(GID.START_LOADING, array(Of Byte)()) players(0).ready = True End Function Public Function receive_GID_PLAYER_READY(ByVal data() As Byte) As Boolean 'this player is ready ready = True say(name + " is ready", Color.Blue) If send_GID_OTHER_PLAYER_READY() = False Then Return False 'look for unready players Dim b As Boolean = True For Each p As BnetGamePlayer In players If p.ready = False Then b = False : Exit For Next p 'launch when all ready If b Then say("All ready", Color.Blue) Return launchLoadedGame() End If Return True End Function Public Function launchLoadedGame() As Boolean say("Launching", Color.Blue) 'send some game data to look good If broadcastPacket(GID.GAME_PACKET, array(Of Byte)(&HFA, &H0)) = False Then Return False 'inform the players that you are leaving If send_GID_PLAYER_LEFT(players(0)) = False Then Return False 'tell them the new host is the second player If send_GID_SET_HOST(players(1)) = False Then Return False 'disconnect For Each p As BnetGamePlayer In copyOfPlayers() If Not p.socket Is Nothing Then p.socket.disconnect() Next p End Function [/code] | January 13, 2008, 12:17 AM |