Exemplo n.º 1
0
        private void ConnectCallback(IAsyncResult ar)
        {
            Socket client = (Socket)ar.AsyncState;

            try
            {
                client.EndConnect(ar);
            }
            catch (SocketException x)
            {
                if (connection != null)
                {
                    connection.Disconnect();
                }
                if (NetConfig.logFilter >= LogFilter.Developer)
                {
                    Log.Debug("Excepiton:" + x.GetErrorCode());
                }
                Connecting = false;
                return;
            }

            catch (Exception e)
            {
                if (connection != null)
                {
                    connection.Disconnect();
                }
                if (NetConfig.logFilter >= LogFilter.Developer)
                {
                    Log.Debug("Excepiton:" + e.ToString());
                }
                Connecting = false;
                return;
            }
            try
            {
                connection.SetHandlers(m_MessageHandlers);
                connection.StartReceiving(client);
                HandShakeMsg packet = new HandShakeMsg
                {
                    Version = NetConfig.Version,
                    OP      = 0,
                };
                connection.Send(InternalMessages.HeandShake_Server, packet);
                Connecting     = false;
                Connected      = true;
                m_RecconectTry = 0;
            }
            catch (Exception e)
            {
                if (NetConfig.logFilter >= LogFilter.Developer)
                {
                    Log.Debug("Excepiton:" + e.ToString());
                }
                Connecting = false;
            }
        }
Exemplo n.º 2
0
        internal void HandleClientHandShake(NetworkMessage netMsg)
        {
            HandShakeMsg packet = netMsg.ReadMessage <HandShakeMsg>();

            if (packet != null)
            {
                if (packet.OP == 0) //VER VERSION
                {
                    netMsg.conn.connectionId = packet.Version;
                    netMsg.conn.stage        = PerStage.Connecting;
                    HandShakeMsg p = new HandShakeMsg
                    {
                        Version = (uint)NetConfig.Key,
                        OP      = 1
                    };
                    netMsg.conn.Send(InternalMessages.HeandShake_Server, p);
                }
                else if (packet.OP == 1)
                {
                    if (packet.Version == NetConfig.Key)
                    {
                        netMsg.conn.stage = PerStage.Connected;
                        HandShakeMsg p = new HandShakeMsg
                        {
                            Version = (uint)NetConfig.Key,
                            OP      = 2
                        };
                        netMsg.conn.Send(InternalMessages.HeandShake_Server, p);
                        ClientConnected = true;
                        connection      = netMsg.conn;
                        PushMessage(new NetworkMessage
                        {
                            msgType = InternalMessages.CONNECTED,
                            conn    = netMsg.conn,
                            reader  = new NetworkReader()
                        });
                    }
                }
            }
        }
Exemplo n.º 3
0
        internal void HandleServerHandShake(NetworkMessage netMsg)
        {
            HandShakeMsg packet = netMsg.ReadMessage <HandShakeMsg>();

            if (packet != null)
            {
                if (packet.OP == 0) //VER VERSION
                {
                    if (packet.Version == NetConfig.Version)
                    {
                        netMsg.conn.stage = PerStage.Verifying;
                        HandShakeMsg p = new HandShakeMsg
                        {
                            Version = netMsg.conn.connectionId,
                            OP      = 0
                        };
                        netMsg.conn.Send(InternalMessages.HeandShake_Client, p);
                    }
                    else
                    {
                        netMsg.conn.Disconnect();
                    }
                }
                else if (packet.OP == 1)
                {
                    if (packet.Version == NetConfig.Key)
                    {
                        netMsg.conn.stage = PerStage.Connecting;
                        HandShakeMsg p = new HandShakeMsg
                        {
                            Version = (uint)NetConfig.Key,
                            OP      = 1
                        };
                        netMsg.conn.Send(InternalMessages.HeandShake_Client, p);
                    }
                    else
                    {
                        netMsg.conn.Disconnect();
                    }
                }
                else if (packet.OP == 2)
                {
                    if (packet.Version == NetConfig.Key)
                    {
                        netMsg.conn.stage = PerStage.Connected;
                        if (NetConfig.logFilter >= LogFilter.Log)
                        {
                            Log.Debug("Connected:" + netMsg.conn.connectionId);
                        }
                        AddConnection(netMsg.conn);
                    }
                    else
                    {
                        netMsg.conn.Disconnect();
                    }
                }
                else
                {
                    netMsg.conn.Disconnect();
                }
            }
        }