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); }
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); }
/// Client or server information come in /// </summary> /// <param name="server"></param> /// <param name="packet"></param> public static void HeartbeatResponse(QRServer server, EndPoint endPoint, byte[] buffer) { byte[] recvKeys = new byte[4]; //we copy 4 bytes information prepare for reply Array.Copy(buffer, 1, recvKeys, 0, 4); byte[] restData = buffer.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.SendAsync(endPoint, sendingBuffer); string errorMsg = string.Format("[HeartBeat] Invalid Server Data Received From {0}:{1}-{2}", server.Endpoint.Address, server.Endpoint.Port, dataFrag[0]); server.ToLog(errorMsg); return; } // We only care about the server data string[] serverDataFrag = serverData.Split(new string[] { "\x00" }, StringSplitOptions.None); //server.ToLog(LogLevel.Debug, string.Format("[QR] [HeartBeat] Data received From {0}", server.Socket.RemoteEndPoint.ToString())); server.ToLog(LogLevel.Debug, string.Format("[QR] [HeartBeat] server info:{0} \t player info:{1} \t team info:{2}", serverData, playerData, teamData)); GameServerData gameServer = new GameServerData(server.Endpoint); // set the country based off ip address if its IPv4 //we set the server variables SetServerVariables(gameServer, serverDataFrag, server.Endpoint); LogWriter.Log.Write("[QR] No impliment function for Heartbeatpacket!", LogLevel.Debug); //TODO }