Esempio n. 1
0
        protected override void DataOperation()
        {
            switch (_reportType)
            {
            case HeartBeatReportType.ServerTeamPlayerData:
                ParseServerTeamPlayerData();
                break;

            case HeartBeatReportType.ServerPlayerData:
                ParseServerPlayerData();
                break;

            case HeartBeatReportType.ServerData:
                ParseServerData();
                break;
            }

            CheckSpamGameServer();

            QRSession client = (QRSession)_session.GetInstance();

            GameServer.UpdateServer(
                client.RemoteEndPoint,
                _gameServer.ServerData.KeyValue["gamename"],
                _gameServer
                );
        }
        protected override void ConstructeResponse()
        {
            if (_session.InstantKey != _request.InstantKey)
            {
                _session.SetInstantKey(_request.InstantKey);
            }

            _sendingBuffer = new QRResponseBase(_request).BuildResponse();

            QRSession client = (QRSession)_session.GetInstance();
            var       result = GameServer.GetServers(client.RemoteEndPoint);

            if (result.Count != 1)
            {
                _errorCode = QRErrorCode.Database;
                return;
            }

            GameServer gameServer = result.First();

            gameServer.LastPacket = DateTime.Now;

            GameServer.UpdateServer
            (
                client.RemoteEndPoint,
                gameServer.ServerData.KeyValue["gamename"],
                gameServer);
        }
Esempio n. 3
0
        protected override void ConstructeResponse()
        {
            KeepAlivePacket packet = new KeepAlivePacket();

            packet.Parse(_recv);
            _sendingBuffer = packet.GenerateResponse();
            QRSession client = (QRSession)_session.GetInstance();
            var       result = GameServer.GetServers(client.RemoteEndPoint);

            if (result.Count != 1)
            {
                _errorCode = Entity.Enumerator.QRErrorCode.Database;
                return;
            }

            GameServer gameServer = result.First();

            gameServer.LastPacket = DateTime.Now;

            GameServer.UpdateServer
            (
                client.RemoteEndPoint,
                gameServer.ServerData.KeyValue["gamename"],
                gameServer);
        }
Esempio n. 4
0
        protected override void DataOperation()
        {
            //TODO
            QRSession client = (QRSession)_session.GetInstance();
            var       result =
                GameServer.GetServers(client.RemoteEndPoint);

            //add recive echo packet on gameserverList
            //DedicatedGameServer game;
            //QRServer.GameServerList.TryGetValue(endPoint, out game);

            if (result == null || result.Count() != 1)
            {
                LogWriter.ToLog(LogEventLevel.Error, "Can not find game server");
                return;
            }

            _gameServer = result.FirstOrDefault();

            _gameServer.LastPacket = DateTime.Now;

            GameServer.UpdateServer(
                client.RemoteEndPoint,
                _gameServer.ServerData.KeyValue["gamename"],
                _gameServer
                );
        }
Esempio n. 5
0
        protected override void ConstructeResponse()
        {
            ChallengePacket packet = new ChallengePacket();
            QRSession       client = (QRSession)_session.GetInstance();

            packet.Parse(client.RemoteEndPoint, _recv);
            _sendingBuffer = packet.GenerateResponse();
        }
Esempio n. 6
0
        protected override void CheckRequest()
        {
            BasePacket basePacket = new BasePacket();

            basePacket.Parse(_recv);
            //DedicatedGameServer gameServer = new DedicatedGameServer();
            //gameServer.Parse(endPoint, basePacket.InstantKey);

            _gameServer = new GameServer();
            QRSession client = (QRSession)_session.GetInstance();

            _gameServer.Parse(client.RemoteEndPoint, basePacket.InstantKey);
            //_gameServer = QRServer.GameServerList.GetOrAdd(endPoint, gameServer);
            //Save server information.
            _dataPartition = Encoding.ASCII.GetString(_recv.Skip(5).ToArray());

            //keep this for debug
            string[] temp = _dataPartition.Split("\0\0", StringSplitOptions.RemoveEmptyEntries);

            _playerPos = _dataPartition.IndexOf("player_\0", StringComparison.Ordinal);
            _teamPos   = _dataPartition.IndexOf("team_t\0", StringComparison.Ordinal);

            if (_playerPos != -1 && _teamPos != -1)
            {
                _reportType = HeartBeatReportType.ServerTeamPlayerData;
            }
            else if (_playerPos != -1)
            {
                //normal heart beat
                _reportType = HeartBeatReportType.ServerPlayerData;
            }
            else if (_playerPos == -1 && _teamPos == -1)
            {
                _reportType = HeartBeatReportType.ServerData;

                //if (PeerGroup.PeerGroupKeyList.Contains(_gameServer.ServerData.KeyValue["gamename"])
                //     && !_gameServer.ServerData.KeyValue.ContainsKey("hostport"))
                //{
                //    _gameServer.IsPeerServer = true;
                //}
                //GameServer.DeleteServer(
                //    endPoint,
                //    _gameServer.ServerData.KeyValue["gamename"]
                //    );
            }
            else
            {
                _errorCode = QRErrorCode.Parse;
                return;
            }


            base.CheckRequest();
        }
 public static bool AddSession(QRSession session)
 {
     if (IsSessionExist(session.RemoteEndPoint))
     {
         return(false);
     }
     else
     {
         return(Sessions.TryAdd(session.RemoteEndPoint, session));
     }
 }
 public static bool GetSession(EndPoint end, out QRSession session)
 {
     if (Sessions.TryGetValue(end, out session))
     {
         return(true);
     }
     else
     {
         session = null;
         return(false);
     }
 }
Esempio n. 9
0
        protected override void DataOperation()
        {
            QRSession client = (QRSession)_session.GetInstance();
            var       result =
                GameServer.GetServers(client.RemoteEndPoint);

            if (result.Count() != 1)
            {
                _errorCode = Entity.Enumerator.QRErrorCode.Database;
                return;
            }
            _gameServer = result.First();
        }
Esempio n. 10
0
        protected override void ConstructeResponse()
        {
            EchoPacket echo = new EchoPacket();

            echo.Parse(_recv);
            // We send the echo packet to check the ping
            _sendingBuffer = echo.GenerateResponse();

            QRSession client = (QRSession)_session.GetInstance();

            GameServer.UpdateServer(
                client.RemoteEndPoint,
                _gameServer.ServerData.KeyValue["gamename"],
                _gameServer
                );
        }
Esempio n. 11
0
        private void CheckSpamGameServer()
        {
            QRSession qrClient = (QRSession)_session.GetInstance();
            //make sure one ip address create one server on each game
            List <string> redisKeys =
                GameServer.GetMatchedKeys(((IPEndPoint)qrClient.RemoteEndPoint).Address
                                          + "*" + _gameServer.ServerData.KeyValue["gamename"]);

            foreach (var key in redisKeys)
            {
                if (key == GameServer.GenerateKey(qrClient.RemoteEndPoint, _gameServer.ServerData.KeyValue["gamename"]))
                {
                    continue;
                }
                GameServer.DeleteServer(key);
            }
        }
Esempio n. 12
0
        protected override void ConstructeResponse()
        {
            EchoPacket packet = new EchoPacket();

            packet.Parse(_recv);
            if (_session.InstantKey != packet.InstantKey)
            {
                _session.SetInstantKey(packet.InstantKey);
            }

            // We send the echo packet to check the ping
            _sendingBuffer = packet.BuildResponse();

            QRSession client = (QRSession)_session.GetInstance();

            GameServer.UpdateServer(
                client.RemoteEndPoint,
                _gameServer.ServerData.KeyValue["gamename"],
                _gameServer
                );
        }
Esempio n. 13
0
 protected QRCommandHandlerBase(ISession session, IRequest request) : base(session)
 {
     _request = request;
     _session = (QRSession)session;
 }
Esempio n. 14
0
 public HeartBeatResponse(QRSession session, HeartBeatRequest request) : base(request)
 {
     RemoteIP   = HtonsExtensions.EndPointToIP(session.RemoteEndPoint);
     RemotePort = HtonsExtensions.EndPointToPort(session.RemoteEndPoint);
     PacketType = QRPacketType.Challenge;
 }
 protected QRCommandHandlerBase(ISession session, byte[] recv) : base(session)
 {
     _recv    = recv;
     _session = (QRSession)session;
 }