public override GPError Parse() { var flag = base.Parse(); if (flag != GPError.NoError) { return(flag); } if (!_rawRequest.ContainsKey("email") && !GameSpyUtils.IsEmailFormatCorrect(_rawRequest["email"])) { return(GPError.Parse); } Email = _rawRequest["email"]; if (_rawRequest.ContainsKey("namespaceid")) { uint namespaceID; if (!uint.TryParse(_rawRequest["namespaceid"], out namespaceID)) { return(GPError.Parse); } NamespaceID = namespaceID; } return(GPError.NoError); }
public static void Switch(GPSPClient client, Dictionary <string, string> recv) { string command = recv.Keys.First(); try { switch (command) { case "search": SearchHandler.SearchUsers(client, recv); break; case "valid": ValidHandler.IsEmailValid(client, recv); break; case "nicks": NickHandler.SearchNicks(client, recv); break; case "pmatch": PmatchHandler.PlayerMatch(client, recv); break; case "check": CheckHandler.CheckProfileid(client, recv); break; case "newuser": NewUserHandler.NewUser(client, recv); break; case "searchunique": SearchUniqueHandler.SearchProfileWithUniquenick(client, recv); break; case "others": OthersHandler.SearchOtherBuddy(client, recv); break; case "otherslist": OthersListHandler.SearchOtherBuddyList(client, recv); break; case "uniquesearch": UniqueSearchHandler.SuggestUniqueNickname(client, recv); break; default: LogWriter.Log.Write("[GPSP] received unknown data " + command, LogLevel.Debug); GameSpyUtils.PrintReceivedGPDictToLogger(command, recv); GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "An invalid request was sended."); break; } } catch (Exception e) { LogWriter.Log.WriteException(e); } }
protected override void OnReceived(string message) { message = RequstFormatConversion(message); if (message[0] != '\\') { GameSpyUtils.SendGPError(this, GPErrorCode.Parse, "An invalid request was sended."); return; } string[] commands = message.Split("\\final\\"); foreach (string command in commands) { if (command.Length < 1) { continue; } // Read client message, and parse it into key value pairs string[] recieved = command.TrimStart('\\').Split('\\'); Dictionary <string, string> dict = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, dict); } }
public override void Parse() { base.Parse(); Password = PasswordEncoder.ProcessPassword(RequestKeyValues); if (!RequestKeyValues.ContainsKey("nick")) { throw new GPParseException("nickname is missing."); } if (!RequestKeyValues.ContainsKey("email")) { throw new GPParseException("email is missing."); } if (!GameSpyUtils.IsEmailFormatCorrect(RequestKeyValues["email"])) { throw new GPParseException("email format is incorrect."); } Nick = RequestKeyValues["nick"]; Email = RequestKeyValues["email"]; if (RequestKeyValues.ContainsKey("uniquenick") && RequestKeyValues.ContainsKey("namespaceid")) { if (RequestKeyValues.ContainsKey("namespaceid")) { int namespaceID; if (!int.TryParse(RequestKeyValues["namespaceid"], out namespaceID)) { throw new GPParseException("namespaceid is incorrect."); } NamespaceID = namespaceID; } Uniquenick = RequestKeyValues["uniquenick"]; } ParseOtherInfo(); }
public void UnknownDataRecived(Dictionary <string, string> recv) { string errorMsg = string.Format("Received unknown data."); ToLog(errorMsg); GameSpyUtils.PrintReceivedGPDictToLogger(recv); }
protected override void CheckRequest() { base.CheckRequest(); if (!_recv.ContainsKey("nick")) { _errorCode = GPErrorCode.Parse; return; } if (!_recv.ContainsKey("email") || !GameSpyUtils.IsEmailFormatCorrect(_recv["email"])) { _errorCode = GPErrorCode.Parse; return; } if (!_recv.ContainsKey("passenc")) { _errorCode = GPErrorCode.Parse; return; } if (_recv.ContainsKey("uniquenick")) { _uniquenick = _recv["uniquenick"]; } }
/// <summary> /// Main listner loop. Keeps an open stream between the client and server while /// the client is logged in / playing /// </summary> protected override void ProcessData(string message) { //message = @"\login\\challenge\l73Iv120dsOnQIA5hCBIqQSkojR191hy\user\retrospy@[email protected]\response\05d45e1b1bf6fbe6b6590785ec8dbe70\port\-9805\productid\10469\gamename\conflictsopc\namespaceid\1\id\1\final\"; message = RequstFormatConversion(message); if (message[0] != '\\') { GameSpyUtils.SendGPError(this, GPErrorCode.General, "An invalid request was sended."); return; } string[] commands = message.Split("\\final\\"); foreach (string command in commands) { if (command.Length < 1) { continue; } // Read client message, and parse it into key value pairs string[] recieved = command.TrimStart('\\').Split('\\'); Dictionary <string, string> dict = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, dict, OnSuccessfulLogin, OnStatusChanged); } }
public static void PlayerMatch(GPSPClient client, Dictionary <string, string> dict) { //pmath\\sesskey\\profileid\\productid\\ string sendingBuffer; if (IsContainAllKey(dict)) { List <Dictionary <string, object> > temp = PmatchQuery.PlayerMatch(dict); if (temp.Count == 1) { sendingBuffer = string.Format(@"\psr\status\{0}\nick\{1}\statuscode\{2}\final\", temp[0]["status"], temp[0]["nick"], temp[0]["statuscode"]); client.Send(sendingBuffer); } else { GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "No match found!"); } } //there are two ways to send information back. //First way: \psr\<profileid>\status\<status>\statuscode\<statuscode>\psrdone\final\ //this is a multiple command. you can contain mutiple \psr\........... in the Steam //Second way:\psr\<profileid>\nick\<nick>\***multiple \psr\ command***\psrdone\final\ //<status> is like the introduction in a player homepage //<statuscode> mean the status information is support or not the value should be as follows //GP_NEW_STATUS_INFO_SUPPORTED = 0xC00, //GP_NEW_STATUS_INFO_NOT_SUPPORTED = 0xC01 }
protected override void CheckRequest(GPSPSession session) { base.CheckRequest(session); if (!_recv.ContainsKey("nick")) { _errorCode = GPErrorCode.Parse; return; } if (!_recv.ContainsKey("email") || !GameSpyUtils.IsEmailFormatCorrect(_recv["email"])) { _errorCode = GPErrorCode.Parse; return; } if (!_recv.ContainsKey("passenc")) { _errorCode = GPErrorCode.Parse; return; } if (_recv.ContainsKey("uniquenick")) { _CreateUserWithUniquenick = true; _uniquenick = _recv["uniquenick"]; } }
public virtual void UnknownDataRecived(string text, Dictionary <string, string> recv) { string errorMsg = string.Format("Received unknown data: {0}", text); GameSpyUtils.PrintReceivedGPDictToLogger(recv); ToLog(errorMsg); }
/// <summary> /// check if a email is exist in database /// </summary> /// <param name="client"></param> /// <param name="dict"></param> public static void IsEmailValid(GPSPClient client, Dictionary <string, string> dict) { if (!dict.ContainsKey("email")) { GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request."); return; } try { if (GameSpyUtils.IsEmailFormatCorrect(dict["email"])) { if (ValidQuery.IsEmailValid(dict)) { client.Send(@"\vr\1\final\"); } else { client.Send(@"\vr\0\final\"); } //client.Stream.Dispose(); } else { client.Send(@"\vr\0\final\"); //client.Stream.Dispose(); } } catch (Exception ex) { LogWriter.Log.WriteException(ex); GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "This request cannot be processed because of a database error."); } }
/// <summary> /// Get profiles that have you on their buddy(friend) list. /// </summary> /// <param name="client"></param> /// <param name="dict"></param> public static void SearchOtherBuddy(GPSPClient client, Dictionary <string, string> dict) { // TODO: Please finis this function //others\sesskey\profileid\namespace\ string sendingbuffer; //= @"\others\o\nick\<>\uniquenick\<>\first\<>\last\<>\email\<>\odone\"; var temp = OthersQuery.GetOtherBuddy(dict); if (temp == null) { GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "No Math Found"); return; } if (temp.Count == 1) { sendingbuffer = string.Format(@"\others\o\nick\{0}\uniquenick\{1}\first\{2}\last\{3}\email\{4}\odone\final\", temp[0]["nick"], temp[0]["uniquenick"], temp[0]["firstname"], temp[0]["lastname"], temp[0]["email"]); client.Stream.SendAsync(sendingbuffer); return; } if (temp.Count > 1) { sendingbuffer = @"\others\"; foreach (Dictionary <string, object> info in temp) { sendingbuffer += string.Format(@"o\nick\{0}\uniquenick\{1}\first\{1}\last\{2}\email\{3}\", info["nick"], info["uniquenick"], info["firstname"], info["lastname"], info["email"]); } client.Stream.SendAsync(sendingbuffer); return; } GameSpyUtils.PrintReceivedGPDictToLogger("others", dict); GameSpyUtils.SendGPError(client, GPErrorCode.General, "This request is not supported yet."); }
public override void CheckRequest() { base.CheckRequest(); //we decoded gamespy encoded password then get md5 of it _password = GameSpyUtils.DecodePassword(_cmd.PasswordHash); _password = StringExtensions.GetMD5Hash(_password); }
public override GPError Parse() { var flag = base.Parse(); if (flag != GPError.NoError) { return(flag); } string md5Password; if (!PasswordEncoder.ProcessPassword(_rawRequest, out md5Password)) { return(GPError.NewUserBadPasswords); } Password = md5Password; if (!_rawRequest.ContainsKey("nick") || !_rawRequest.ContainsKey("email") || Password == null) { return(GPError.Parse); } if (!GameSpyUtils.IsEmailFormatCorrect(_rawRequest["email"])) { return(GPError.CheckBadMail); } Nick = _rawRequest["nick"]; Email = _rawRequest["email"]; return(GPError.NoError); }
/// <summary> /// This function is fired when data is received from a stream /// </summary> /// <param name="stream">The stream that sended the data</param> /// <param name="message">The message the stream sended</param> protected override void ProcessData(string message) { //message= @"\search\sesskey\0\profileid\0\namespaceid\1\email\[email protected]\gamename\conflictsopc\final\"; message = RequstFormatConversion(message); if (message[0] != '\\') { GameSpyUtils.SendGPError(this, GPErrorCode.Parse, "An invalid request was sended."); return; } string[] commands = message.Split("\\final\\"); foreach (string command in commands) { if (command.Length < 1) { continue; } // Read client message, and parse it into key value pairs string[] recieved = command.TrimStart('\\').Split('\\'); Dictionary <string, string> dict = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, dict); } }
/// <summary> /// Called when a connection comes in on the CDKey server /// known messages /// \ka\ = keep alive from the game server every 20s, we don't care about this /// \auth\ ... = authenticate cd key, this is what we care about /// \disc\ ... = disconnect cd key, because there's checks if the cd key is in use, which we don't care about really, but we could if we wanted to /// </summary> protected override void OnReceived(EndPoint endPoint, byte[] message) { string decrypted = Enctypex.XorEncoding(message, 0); decrypted.Replace(@"\r\n", "").Replace("\0", ""); string[] recieved = decrypted.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, endPoint, recv); }
protected override void ProcessRawRequest() { if (_rawRequest[0] != '\\') { throw new UniSpyException("Invalid request"); } var name = GameSpyUtils.ConvertToKeyValue(_rawRequest).Keys.First(); _requests.Add(new KeyValuePair <object, object>(name, _rawRequest)); }
protected override void CheckRequest(GPSPSession session) { if (!_recv.ContainsKey("email")) { _errorCode = GPErrorCode.Parse; } if (!GameSpyUtils.IsEmailFormatCorrect(_recv["email"])) { _errorCode = GPErrorCode.Parse; } }
protected override void OnReceived(string message) { if (message[0] != '\\') { return; } string[] recieved = message.TrimStart('\\').Split('\\'); Dictionary <string, string> dict = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, dict); }
protected override void CheckRequest() { if (!_recv.ContainsKey("nick") || !_recv.ContainsKey("email") || !_recv.ContainsKey("passenc")) { _errorCode = GPErrorCode.Parse; } if (!GameSpyUtils.IsEmailFormatCorrect(_recv["email"])) { _errorCode = GPErrorCode.CheckBadMail; } }
public static void Switch(ISession session, string rawRequest) { try { if (rawRequest[0] != '\\') { return; } string[] requestFraction = rawRequest.TrimStart('\\').Split('\\'); var request = GameSpyUtils.ConvertRequestToKeyValue(requestFraction); switch (request.Keys.First()) { case GStatsRequestName.AuthenticateUser: new AuthHandler(session, request).Handle(); break; case GStatsRequestName.AuthenticatePlayer: new AuthPHandler(session, request).Handle(); break; case GStatsRequestName.GetProfileID: new GetPIDHandler(session, request).Handle(); break; case GStatsRequestName.GetPlayerData: new GetPDHandler(session, request).Handle(); break; case GStatsRequestName.SetPlayerData: new SetPDHandler(session, request).Handle(); break; case GStatsRequestName.UpdateGameData: new UpdGameHandler(session, request).Handle(); break; case GStatsRequestName.CreateNewGamePlayerData: new NewGameHandler(session, request).Handle(); break; default: LogWriter.UnknownDataRecieved(rawRequest); break; } } catch (Exception e) { LogWriter.ToLog(LogEventLevel.Error, e.ToString()); } }
public void Switch(GStatsSession session, string message) { try { if (message[0] != '\\') { return; } string[] recieved = message.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertRequestToKeyValue(recieved); switch (recv.Keys.First()) { case "auth": new AuthHandler().Handle(session, recv); break; case "authp": new AuthPHandler().Handle(session, recv); break; case "getpid": new GetPidHandler().Handle(session, recv); break; case "getpd": //get player data new GetPDHandler().Handle(session, recv); break; case "setpd": new SetPDHandler().Handle(session, recv); break; case "updgame": new UpdGameHandler().Handle(session, recv); break; case "newgame": new NewGameHandler().Handle(session, recv); break; default: LogWriter.UnknownDataRecieved(message); break; } } catch (Exception e) { LogWriter.ToLog(e); } }
/// <summary> /// This function is fired when data is received from a stream /// </summary> /// <param name="stream">The stream that sended the data</param> /// <param name="message">The message the stream sended</param> protected override void ProcessData(string message) { message = message.Replace(@"\final\", ""); string decodedmsg = GameSpyLib.Extensions.Enctypex.XorEncoding(message, 1); if (decodedmsg[0] != '\\') { return; } string[] recieved = decodedmsg.TrimStart('\\').Split('\\'); Dictionary <string, string> dict = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, dict); }
/// <summary> /// First we need to check the format of email,nick,uniquenick is correct /// and search uniquenick to find if a account is existed /// </summary> /// <returns></returns> public static GPErrorCode IsEmailNickUniquenickValied(Dictionary <string, string> dict) { if (!GameSpyUtils.IsNickOrUniquenickFormatCorrect(dict["nick"])) { return(GPErrorCode.NewUserBadNick); } if (dict.ContainsKey("uniquenick")) { if (!GameSpyUtils.IsNickOrUniquenickFormatCorrect(dict["uniquenick"])) { return(GPErrorCode.NewUserUniquenickInvalid); } } return(GPErrorCode.NoError); }
/// <summary> /// Get nickname through email and password /// </summary> /// <param name="client"></param> /// <param name="dict"></param> public static void SearchNicks(GPSPClient client, Dictionary <string, string> dict) { //Format the password for our database storage //if not recieved correct request we terminate GPErrorCode error = IsSearchNicksContianAllKeys(dict); if (error != GPErrorCode.NoError) { GameSpyUtils.SendGPError(client, (int)error, "Error recieving SearchNicks request."); return; } List <Dictionary <string, object> > queryResult; try { //get nicknames from GPSPDBQuery class queryResult = NickQuery.RetriveNicknames(dict); } catch (Exception ex) { LogWriter.Log.Write(ex.Message, LogLevel.Error); GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "This request cannot be processed because of a database error."); return; } if (queryResult.Count < 1) { GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "No match found !"); return; } string sendingBuffer; sendingBuffer = @"\nr\"; foreach (Dictionary <string, object> row in queryResult) { sendingBuffer += @"\nick\"; sendingBuffer += row["nick"]; sendingBuffer += @"\uniquenick\"; sendingBuffer += row["uniquenick"]; } sendingBuffer += @"\ndone\final\"; client.Stream.SendAsync(sendingBuffer); }
public override GPError Parse() { var flag = base.Parse(); if (flag != GPError.NoError) { return(flag); } string md5Password; if (!PasswordEncoder.ProcessPassword(_rawRequest, out md5Password)) { return(GPError.NewUserBadPasswords); } Password = md5Password; if (!_rawRequest.ContainsKey("nick")) { return(GPError.Parse); } if (!_rawRequest.ContainsKey("email") || !GameSpyUtils.IsEmailFormatCorrect(_rawRequest["email"])) { return(GPError.Parse); } Nick = _rawRequest["nick"]; Email = _rawRequest["email"]; if (_rawRequest.ContainsKey("uniquenick") && _rawRequest.ContainsKey("namespaceid")) { if (_rawRequest.ContainsKey("namespaceid")) { uint namespaceID; if (!uint.TryParse(_rawRequest["namespaceid"], out namespaceID)) { return(GPError.Parse); } NamespaceID = namespaceID; } Uniquenick = _rawRequest["uniquenick"]; } return(ParseOtherInfo()); }
private static bool IsContainAllKey(Dictionary <string, string> dict) { if (dict.ContainsKey("sesskey") && dict.ContainsKey("profileid") && dict.ContainsKey("productid")) { if (GameSpyUtils.IsNumber(dict["sesskey"]) && GameSpyUtils.IsNumber(dict["profileid"]) && GameSpyUtils.IsNumber(dict["productid"])) { return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Called when a connection comes in on the CDKey server /// known messages /// \ka\ = keep alive from the game server every 20s, we don't care about this /// \auth\ ... = authenticate cd key, this is what we care about /// \disc\ ... = disconnect cd key, because there's checks if the cd key is in use, which we don't care about really, but we could if we wanted to /// </summary> protected override void ProcessAccept(UDPPacket packet) { // If we dont reply, we must manually release the EventArgs back to the pool Replied = false; try { // Decrypt message IPEndPoint remote = (IPEndPoint)packet.AsyncEventArgs.RemoteEndPoint; string decrypted = Enctypex.XorEncoding(packet.BytesRecieved, 0).Trim('\\'); string[] recieved = decrypted.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); switch (recieved[0]) { //keep client alive request, we skip this case "ka": case "auth": case "resp": case "skey": CDKeyHandler.IsCDKeyValid(this, packet, recv); break; case "disc": CDKeyHandler.DisconnectRequest(packet, recv); break; default: CDKeyHandler.InvalidCDKeyRequest(this, packet, recv); break; } } catch (Exception e) { LogWriter.Log.WriteException(e); } finally { // Release so that we can pool the EventArgs to be used on another connection if (!Replied) { Release(packet.AsyncEventArgs); } } }
public void Switch(ISession client, string message) { message.Replace(@"\r\n", "").Replace("\0", ""); string[] keyValueArray = message.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertRequestToKeyValue(keyValueArray); try { switch (recv.Keys.First()) { //keep client alive request, we skip this case "ka": Console.WriteLine("Received keep alive command"); break; case "auth": break; case "resp": break; case "skey": SKeyHandler.IsCDKeyValid(client, recv); break; case "disc": //disconnect from server break; case "uon": break; default: LogWriter.UnknownDataRecieved(message); break; } } catch (Exception e) { LogWriter.ToLog(e); } }
public override void Parse() { base.Parse(); Password = PasswordEncoder.ProcessPassword(RequestKeyValues); if (!RequestKeyValues.ContainsKey("nick") || !RequestKeyValues.ContainsKey("email") || Password is null) { throw new GPParseException("check request is incompelete."); } if (!GameSpyUtils.IsEmailFormatCorrect(RequestKeyValues["email"])) { throw new GPParseException("email format is incorrect"); } Nick = RequestKeyValues["nick"]; Email = RequestKeyValues["email"]; if (RequestKeyValues.ContainsKey("partnerid")) { PartnerId = int.Parse(RequestKeyValues["partnerid"]); } }