Ejemplo n.º 1
0
 internal void ReceiveMessage(byte[] data, ServerSocket con)
 {
     //Debug.WriteLine("[Message] {0}", data[4]);
     // Check if this is the first message received
     if (!State.Instance.SaidHello(con))
     {
         var acceptableMessages = new byte[]
             {
                 1, // Error
                 4, // Hello
                 5, // HelloAgain
                 92, // Ping
             };
         //TODO Maybe we shouldn't kill the connection here
         //     Basically, if someone dc's it's possible that
         //     a network call gets sent up on accident before HelloAgain,
         //     which effectivly kills the game.
         //     Maybe need a flag on the player saying they at least said
         //     hello once.
         // A new connection must always start with a hello message, refuse the connection
         if (acceptableMessages.Contains(data[4]) == false)
         {
             var pi = State.Instance.GetClient(con);
             pi.Kick(false, L.D.ServerMessage__FailedToSendHelloMessage);
             State.Instance.RemoveClient(pi);
             return;
         }
     }
     // Set the lSender field
     _sender = con;
     _sender.OnPingReceived();
     // Parse and handle the message
     _binParser.Parse(data);
 }
Ejemplo n.º 2
0
Archivo: Server.cs Proyecto: wlk0/OCTGN
 private async Task ListenSingle()
 {
     try {
         TcpClient client = null;
         try {
             client = await _tcp.AcceptTcpClientAsync();
         } catch (ObjectDisposedException) {
             return;
         }
         if (client != null)
         {
             Log.InfoFormat("New Connection {0}", client.Client.RemoteEndPoint);
             var sc = new ServerSocket(client, this);
             Context.State.Players.AddClient(sc);
             return;
         }
         throw new NotImplementedException();
     } catch (SocketException e) {
         if (e.SocketErrorCode != SocketError.Interrupted)
         {
             throw;
         }
     }
 }
Ejemplo n.º 3
0
 internal void SetupHandler(ServerSocket con)
 {
     // Set the lSender field
     _sender = con;
 }
Ejemplo n.º 4
0
 // Main thread function: waits and accept incoming connections
 private void Listen(object o)
 {
     // Retrieve the parameter
     var started = (ManualResetEvent)o;
     // Start the server and signal it
     _tcp.Start();
     started.Set();
     try
     {
         while (!_closed)
         {
             // Accept new connections
             var con = _tcp.AcceptTcpClient();
             if (con != null)
             {
                 var sc = new ServerSocket(con, this);
                 State.Instance.AddClient(sc);
             }
         }
     }
     catch (SocketException e)
     {
         // Interrupted is expected when the server gets stopped
         if (e.SocketErrorCode != SocketError.Interrupted) throw;
     }
 }
Ejemplo n.º 5
0
 internal void ResetSocket(ServerSocket socket)
 {
     Socket = socket;
 }
Ejemplo n.º 6
0
 internal PlayerInfo(ServerSocket socket)
 {
     Socket = socket;
     Connected = true;
 }
Ejemplo n.º 7
0
 internal void ReceiveMessage(byte[] data, ServerSocket con)
 {
     //Debug.WriteLine("[Message] {0}", data[4]);
     // Check if this is the first message received
     if (!State.Instance.SaidHello(con))
     {
         // A new connection must always start with a hello message, refuse the connection
         if (data[4] != (byte)3 && data[4] != (byte)4)
         {
             var pi = State.Instance.GetClient(con);
             pi.Kick("You must shake hands. No one likes an anti social connection.");
             State.Instance.RemoveClient(pi);
             return;
         }
     }
     // Set the lSender field
     _sender = con;
     _sender.OnPingReceived();
     // Parse and handle the message
     _binParser.Parse(data);
 }
Ejemplo n.º 8
0
 public PlayerInfo GetClient(ServerSocket client)
 {
     return Clients.FirstOrDefault(x => x.Socket == client);
 }
Ejemplo n.º 9
0
 public PlayerInfo GetClient(ServerSocket client)
 {
     return(Clients.FirstOrDefault(x => x.Socket == client));
 }
Ejemplo n.º 10
0
 internal void ResetSocket(ServerSocket socket)
 {
     Socket = socket;
 }
Ejemplo n.º 11
0
 internal PlayerInfo(ServerSocket socket)
 {
     Socket    = socket;
     Connected = true;
 }
Ejemplo n.º 12
0
 public BinaryParser(ServerSocket socket)
 {
     _socket = socket ?? throw new ArgumentNullException(nameof(socket));
 }
Ejemplo n.º 13
0
 public BinarySenderStub(ServerSocket to, Handler handler) : base(handler)
 {
     this.to = to;
 }
Ejemplo n.º 14
0
 public BinarySenderStub(ServerSocket to, Handler handler)
     : base(handler)
 {
     this.to = to;
 }
Ejemplo n.º 15
0
 public bool SaidHello(ServerSocket socket)
 {
     return(SaidHello(socket.Client));
 }
Ejemplo n.º 16
0
 public void AddClient(ServerSocket socket)
 {
     try
     {
         _locker.EnterWriteLock();
         _players.Add(new PlayerInfo(socket));
     }
     finally
     {
         _locker.ExitWriteLock();
     }
 }
Ejemplo n.º 17
0
 internal void SetupHandler(ServerSocket con)
 {
     // Set the lSender field
     _sender = con;
 }
Ejemplo n.º 18
0
 public bool SaidHello(ServerSocket socket)
 {
     return SaidHello(socket.Client);
 }
Ejemplo n.º 19
0
 internal PlayerInfo(State state, ServerSocket socket)
 {
     _state    = state;
     Socket    = socket;
     Connected = true;
 }