예제 #1
0
        public static void Switch(QRServer server, EndPoint endPoint, byte[] recv)
        {
            try
            {
                switch (recv[0])
                {
                case QRClient.Avaliable:
                    AvailableCheckHandler.BackendAvaliabilityResponse(server, endPoint, recv);
                    break;

                // Note: BattleSpy make use of this despite not being used in both OpenSpy and the SDK.
                // Perhaps it was present on an older version of GameSpy SDK
                case QRGameServer.Challenge:
                    ChallengeHandler.ServerChallengeResponse(server, endPoint, recv);
                    break;

                case QRClient.Heartbeat:     // HEARTBEAT
                    HeartBeatHandler.HeartbeatResponse(server, endPoint, recv);
                    break;

                case QRClient.KeepAlive:
                    KeepAliveHandler.KeepAliveResponse(server, endPoint, recv);
                    break;

                default:
                    server.UnknownDataRecived(recv);
                    break;
                }
            }
            catch (Exception e)
            {
                LogWriter.Log.WriteException(e);
                server.ReceiveAsync();
            }
        }
예제 #2
0
 /// <summary>
 /// Starts a specific server
 /// </summary>
 /// <param name="cfg">The configuration of the specific server to run</param>
 protected override void StartServer(ServerConfig cfg)
 {
     if (cfg.Name == ServerName)
     {
         // case "GPCM":
         Server = new QRServer(IPAddress.Parse(cfg.ListeningAddress), cfg.ListeningPort).Start();
         Console.WriteLine(
             UniSpyLib.Extensions.StringExtensions.FormatServerTableContext(cfg.Name, cfg.ListeningAddress, cfg.ListeningPort.ToString()));
     }
 }
예제 #3
0
 /// <summary>
 /// Starts a specific server
 /// </summary>
 /// <param name="cfg">The configuration of the specific server to run</param>
 protected override void StartServer(ServerConfiguration cfg)
 {
     //if (cfg.Disabled)
     //    return;
     //LogWriter.Log.Write("Starting {2} server at  {0}:{1}.", LogLevel.Info, cfg.Hostname, cfg.Port, cfg.Name);
     //LogWriter.Log.Write("Maximum connections for {0} are {1}.", LogLevel.Info, cfg.Name, cfg.MaxConnections);
     if (cfg.Name == ServerName)
     {
         // case "GPCM":
         Server = new QRServer(cfg.Name, databaseDriver, IPAddress.Parse(cfg.Hostname), cfg.Port);
         LogWriter.Log.Write(LogLevel.Info, "|{0,-11}|{1,-14}|{2,-6}|", cfg.Name, cfg.Hostname, cfg.Port);
     }
 }
예제 #4
0
 public static void KeepAliveResponse(QRServer server, EndPoint endPoint, byte[] buffer)
 {
     byte[] sendingBuffer = new byte[7];
     sendingBuffer[0] = QR.QRMagic1;
     sendingBuffer[1] = QR.QRMagic2;
     sendingBuffer[2] = QRClient.KeepAlive;
     //According to SDK we know the instant key is from packet.BytesRecieved[1] to packet.BytesRecieved[4]
     //So we add it to response
     Array.Copy(buffer, 1, sendingBuffer, 3, 4);
     server.Send(endPoint, sendingBuffer);
     //We should keep the dedicated server in our server list
     //TODO
     LogWriter.Log.Write("[QR] Not finish function for KeepAlivePacket!", LogLevel.Debug);
 }
예제 #5
0
        public static void ServerChallengeResponse(QRServer server, EndPoint endPoint, byte[] buffer)
        {
            byte[] challenge   = new byte[90];
            byte[] instancekey = new byte[4];

            Array.Copy(buffer, 1, instancekey, 0, 4);

            byte[] sendingbuffer = new byte[7];
            sendingbuffer[0] = QR.QRMagic1;
            sendingbuffer[1] = QR.QRMagic2;
            sendingbuffer[2] = QRGameServer.ClientRegistered;
            Array.Copy(instancekey, 0, sendingbuffer, 3, 4);

            server.SendAsync(endPoint, sendingbuffer);

            LogWriter.Log.Write("[QR] No impliment function for ServerChallengeResponse!", LogLevel.Debug);
        }
예제 #6
0
        /// <summary>
        /// Client or server information come in
        /// </summary>
        /// <param name="server"></param>
        /// <param name="packet"></param>
        public static void HeartbeatResponse(QRServer server, UDPPacket packet)
        {
            IPEndPoint remote = (IPEndPoint)packet.AsyncEventArgs.RemoteEndPoint;

            byte[] recvKeys = new byte[4];
            //we copy 4 bytes information prepare for reply
            Array.Copy(packet.BytesRecieved, 1, recvKeys, 0, 4);


            byte[] restData = packet.BytesRecieved.Skip(5).ToArray();
            string recvData = Encoding.UTF8.GetString(restData);

            string[] dataFrag;
            string   serverData, playerData, teamData;

            if (IsServerDataValid(recvData, out dataFrag))
            {
                serverData = dataFrag[0];
                playerData = dataFrag[1];
                teamData   = dataFrag[2];
            }
            else
            {
                //we revieved a wrong data, we have to send challege to game server
                byte[] sendingBuffer = GenerateChallenge(recvKeys);

                server.Send(packet, sendingBuffer);
                server.Replied = true;
                LogWriter.Log.Write(LogLevel.Debug, "[QR] [HeartBeat] Invalid Server Data Received From {0}:{1}-{2}", remote.Address, remote.Port, dataFrag[0]);
                return;
            }
            // We only care about the server data
            string[] serverDataFrag = serverData.Split(new string[] { "\x00" }, StringSplitOptions.None);
            LogWriter.Log.Write(LogLevel.Debug, "[QR] [HeartBeat] Data received From {0}:{1}", remote.Address, remote.Port);
            LogWriter.Log.Write(LogLevel.Debug, "[QR] [HeartBeat] server info:{0} \t player info:{1} \t team info:{2}", serverData, playerData, teamData);

            GameServer gameServer = new GameServer(remote);

            // set the country based off ip address if its IPv4

            //we set the server variables
            SetServerVariables(gameServer, serverDataFrag, remote);

            LogWriter.Log.Write("[QR] No impliment function for Heartbeatpacket!", LogLevel.Debug);
            //TODO
        }
        public static void BackendAvaliabilityResponse(QRServer server, UDPPacket packet)
        {
            if (!IsClientRequestValid(packet.BytesRecieved))
            {
                // ???
                return;
            }

            //string gameName = GetGameName(packet.BytesRecieved);

            byte[] dataToSend = new byte[7];
            AvailableReply.CopyTo(dataToSend, 0);

            // NOTE: Change this if you want to make the server not avaliable.
            dataToSend[6] = (byte)ServerAvaliability.Avaliable;

            //packet.SetBufferContents(dataToSend);
            server.Send(packet, dataToSend);
        }
예제 #8
0
        public static void BackendAvaliabilityResponse(QRServer server, EndPoint endPoint, byte[] buffer)
        {
            if (!IsClientRequestValid(buffer))
            {
                // ???
                return;
            }

            //string gameName = GetGameName(packet.BytesRecieved);

            byte[] sendingBuffer = new byte[7];
            AvailableReply.CopyTo(sendingBuffer, 0);

            // NOTE: Change this if you want to make the server not avaliable.
            sendingBuffer[6] = (byte)ServerAvailability.Available;

            //packet.SetBufferContents(dataToSend);
            server.SendAsync(endPoint, sendingBuffer);
        }