Esempio n. 1
0
        private void OnClientConnect(IAsyncResult result)
        {
            try
            {
                Socket clientSocket = Socket.EndAccept(result);

                /* WebClient c = new WebClient();
                 * c.DownloadStringCompleted +=
                 *  (sender, e) =>
                 *  {
                 *      Console.WriteLine("[UCS]    Client connected (" +
                 *                        ((IPEndPoint) clientSocket.RemoteEndPoint).Address + ", " + e.Result.Trim() +
                 *                        ")");
                 *  };
                 * c.DownloadStringAsync(
                 *  new Uri("http://ipinfo.io/" + ((IPEndPoint) clientSocket.RemoteEndPoint).Address + "/country"));
                 *
                 */
                Console.WriteLine("[UCS]    Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + ")");
                ResourcesManager.AddClient(new Client(clientSocket),
                                           ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
                SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
                Socket.BeginAccept(OnClientConnect, Socket);
            }
            catch (Exception e)
            {
                Debugger.WriteLine("[UCS]    Exception when accepting incoming connection", e);
            }
        }
Esempio n. 2
0
File: Gateway.cs Progetto: skwbr/UCS
 void OnClientConnect(IAsyncResult ar)
 {
     allDone.Set();
     try
     {
         Socket listener     = (Socket)ar.AsyncState;
         Socket clientSocket = listener.EndAccept(ar);
         _Logger.Print("[UCS]    Player connected -> " + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + "", Types.ERROR);
         ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
         SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
     }
     catch (Exception e)
     {
     }
 }
Esempio n. 3
0
File: Gateway.cs Progetto: skwbr/UCS
 static void OnReceive(SocketRead read, byte[] data)
 {
     try
     {
         Client c = ResourcesManager.GetClient(read.Socket.Handle.ToInt64());
         c.DataStream.AddRange(data);
         Message p;
         while (c.TryGetPacket(out p))
         {
             PacketManager.ProcessIncomingPacket(p);
         }
     }
     catch (Exception ex)
     {
     }
 }
Esempio n. 4
0
 void OnClientConnect(IAsyncResult ar)
 {
     allDone.Set();
     try
     {
         Socket listener     = (Socket)ar.AsyncState;
         Socket clientSocket = listener.EndAccept(ar);
         Console.WriteLine("[UCS]    Player connected " + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + "");
         ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
         SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
     }
     catch (Exception e)
     {
         //Debugger.WriteLine("[UCS]    Exception when accepting incoming connection", e);
     }
 }
Esempio n. 5
0
 private static void OnReceive(SocketRead read, byte[] data)
 {
     try
     {
         Client c = ResourcesManager.GetClient(read.Socket.Handle.ToInt64());
         c.DataStream.AddRange(data);
         Message p;
         while (c.TryGetPacket(out p))
         {
             PacketManager.ProcessIncomingPacket(p);
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteLine("[UCS]    Exception thrown when processing incoming packet : ", ex);
     }
 }
Esempio n. 6
0
File: Gateway.cs Progetto: skwbr/UCS
 static void OnReceiveError(SocketRead read, Exception exception)
 {
 }
Esempio n. 7
0
 private static void OnReceiveError(SocketRead read, Exception exception)
 {
     Debugger.WriteLine(
         "[UCS]    The client '" + ((IPEndPoint)read.Socket.RemoteEndPoint).Address + "' throw an exception",
         exception);
 }
Esempio n. 8
0
        //void OnReceive(SocketRead read, byte[] data)
        //{

        //    try
        //    {
        //        long socketHandle = read.Socket.Handle.ToInt64();
        //        Client c = ResourcesManager.GetClient(socketHandle);
        //        c.DataStream.AddRange(data);

        //        Message p;

        //        while (c.TryGetPacket(out p))
        //        {
        //            PacketManager.ProcessIncomingPacket(p);
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        //Client may not exist anymore
        //        Debug.Write(e);
        //    }
        //}
        //private void OnReceive(IAsyncResult _Ar)
        //{
        //    try
        //    {
        //        SocketError _Status = 0;
        //        int _Readed = this.m_vServerSocket.EndReceive(_Ar, out _Status);

        //        if (_Status == SocketError.Success && _Readed > 0)
        //        {
        //            byte[] _Read = new byte[_Readed];
        //            Array.Copy(this.Buffer, 0, _Read, 0, _Readed);
        //            this.RHandler(this, _Read);
        //            this.m_vServerSocket.BeginReceive(this.Buffer, 0, Constants.MaxBuffer, 0, this.OnReceive, this);
        //        }
        //    }
        //    catch (Exception)
        //    {
        //Client _Client = ResourcesManager.GetClient([this.m_vServerSocket.Handle]);

        //if (_Client != null)
        //{
        //    _Client.Errors = _Client.Errors + 1;

        //    if (_Client.Level != null)
        //    {
        //        Console.WriteLine("The player " + _Client.Level.PlayerID + " [" + _Client.Level.Name + "] throwed an exception.");
        //    }
        //    else
        //    {
        //        Console.WriteLine("The player with IP " + this.m_vServerSocket.RemoteEndPoint + " throwed an exception.");
        //    }
        //}
        //else
        //{
        //Console.WriteLine("The player with IP " + this.m_vServerSocket.RemoteEndPoint + " throwed an exception.");
        //}
        //    }
        //}
        void OnReceiveError(SocketRead read, System.Exception exception)
        {
            Debug.Write("Error received: " + exception);
        }