Ejemplo n.º 1
0
        void ssc_SClientConnected(object sender, ClientConnectedEventArgs e)
        {
            SharpStarServerClient ssc = e.Client.Server;

            _clients.Add(ssc);

            if (ClientConnected != null)
            {
                ClientConnected(this, new ClientConnectedEventArgs(ssc.PlayerClient));
            }

            ssc.ServerClient.InternalClientDisconnected += ServerClient_ClientDisconnected;
        }
Ejemplo n.º 2
0
        private void ProcessAccept(SocketAsyncEventArgs e)
        {
            SocketAsyncEventArgs readEventArgs = new SocketAsyncEventArgs();

            readEventArgs.UserToken = new AsyncUserToken();

            byte[] buffer = new byte[1024];
            readEventArgs.SetBuffer(buffer, 0, buffer.Length);

            ((AsyncUserToken)readEventArgs.UserToken).Socket = e.AcceptSocket;

            if (!e.AcceptSocket.Connected)
            {
                StartAccept(e);

                return;
            }

            SharpStarLogger.DefaultLogger.Info("Connection from {0}", e.AcceptSocket.RemoteEndPoint);

            Interlocked.Increment(ref m_numConnectedSockets);

            StartAccept(e);

            try
            {
                SharpStarClient client = new SharpStarClient(readEventArgs, Direction.Client);
                client.InternalClientDisconnected += PlayerClient_ClientDisconnected;

                SharpStarServerClient ssc = new SharpStarServerClient(client);
                ssc.SClientConnected += ssc_SClientConnected;
                ssc.ClientId          = m_numConnectedSockets;

                foreach (IPacketHandler packetHandler in DefaultPacketHandlers)
                {
                    ssc.RegisterPacketHandler(packetHandler);
                }

                ssc.Connect(sbServerEndPoint);
            }
            catch (Exception ex)
            {
                ex.LogError();
            }
        }