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); }
/// <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 ServerChallengeResponse(QRServer server, UDPPacket packet) { byte[] challenge = new byte[90]; byte[] instancekey = new byte[4]; Array.Copy(packet.BytesRecieved, 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.Send(packet, sendingbuffer); LogWriter.Log.Write("[QR] No impliment function for ServerChallengeResponse!", LogLevel.Debug); }
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); }