コード例 #1
0
 public static void Reset()
 {
     readyPlayers   = 0;
     currentPlayers = 0;
     isGameStarted  = false;
     for (int i = 0; i < 2; i++)
     {
         score[i] = 0;
     }
     RouterServer.Initialize();
     Server.Initialize();
 }
コード例 #2
0
        public void _Disconnect()
        {
            if (tcp.clientSocket != null)
            {
                Console.WriteLine($"{tcp.clientSocket.Client.RemoteEndPoint} has disconnected.");
                if (player.isReady)
                {
                    GameLogic.readyPlayers--;
                }
                GameLogic.currentPlayers--;
                player = null;
                tcp.Disconnect();
                udp.Disconnect();
                ServerSend.KickPlayerToAllExcept(id);

                Server.Initialize(id);
            }
        }
コード例 #3
0
            private void _ReceiveCallback(IAsyncResult _result)
            {
                try
                {
                    int _dataLength = stream.EndRead(_result);
                    if (_dataLength <= 0)
                    {
                        Server.clients[id]._Disconnect();
                        return;
                    }

                    byte[] _data = new byte[_dataLength];
                    Array.Copy(receiveBuffer, _data, _dataLength);

                    receivedPacket.Reset(_HandleData(_data));
                    stream.BeginRead(receiveBuffer, 0, dataBufferSize, _ReceiveCallback, null);
                }
                catch (Exception _ex)
                {
                    Console.WriteLine($"Error receiving TCP data: {_ex}");
                    Server.Initialize(id);
                }
            }