Esempio n. 1
0
        private void _Disconnect()
        {
            Console.WriteLine($"{tcp.clientSocket.Client.RemoteEndPoint} has disconnected from router server.");
            tcp.Disconnect();

            RouterServer.Initialize(id);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.Title = "Game Server";
            isRunning     = true;

            Thread mainThread = new Thread(new ThreadStart(_MainThread));

            mainThread.Start();

            RouterServer.Start(12);
            Server.Start(12);
        }
Esempio n. 3
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();
 }
Esempio n. 4
0
            private void _ReceiveCallback(IAsyncResult _result)
            {
                try
                {
                    int _dataLength = stream.EndRead(_result);
                    if (_dataLength <= 0)
                    {
                        RouterServer.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}");
                    RouterServer.Initialize(id);
                }
            }