/// <summary> /// Whenever the "newuser" command is recieved, this method is called to /// add the new users information into the database /// </summary> /// <param name="Recv">Array of parms sent by the server</param> private void CreateNewUser(Dictionary <string, string> Recv) { // Make sure the user doesnt exist already try { using (GamespyDatabase Database = new GamespyDatabase()) { // Check to see if user exists if (Database.UserExists(Recv["nick"])) { Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\This account name is already in use!\id\1\final\"); Disconnect(5); return; } // We need to decode the Gamespy specific encoding for the password string Password = GamespyUtils.DecodePassword(Recv["passwordenc"]); string Cc = (RemoteEndPoint.AddressFamily == AddressFamily.InterNetwork) ? Ip2nation.GetCountryCode(RemoteEndPoint.Address) : Program.Config.ASP_LocalIpCountryCode; // Attempt to create account. If Pid is 0, then we couldnt create the account if ((PlayerId = Database.CreateUser(Recv["nick"], Password, Recv["email"], Cc)) == 0) { Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\Error creating account!\id\1\final\"); Disconnect(6); return; } Stream.SendAsync(@"\nur\\userid\{0}\profileid\{0}\id\1\final\", PlayerId); } } catch (Exception e) { // Check for invalid query params if (e is KeyNotFoundException) { Stream.SendAsync(@"\error\\err\0\fatal\\errmsg\Invalid Query!\id\1\final\"); } else { Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\Error creating account!\id\1\final\"); GpcmServer.Log("ERROR: [Gpcm.CreateNewUser] An error occured while trying to create a new User account :: " + e.Message); } Disconnect(7); return; } }
/// <summary> /// This method is requested by the client when logging in to fetch all the account /// names that have the specified email address and password combination /// </summary> /// <param name="recvData"></param> private void SendNicks(Dictionary <string, string> recvData) { // Make sure we have the needed data if (!recvData.ContainsKey("email") || (!recvData.ContainsKey("pass") && !recvData.ContainsKey("passenc"))) { Stream.SendAsync(@"\error\\err\0\fatal\\errmsg\Invalid Query!\id\1\final\"); return; } // Try to get user data from database try { // Get our password from the provided query string password = (recvData.ContainsKey("pass")) ? recvData["pass"] : GamespyUtils.DecodePassword(recvData["passenc"]); // Fetch accounts using (GamespyDatabase Db = new GamespyDatabase()) { var Clients = Db.GetUsersByEmailPass(recvData["email"], password.GetMD5Hash(false)); StringBuilder Response = new StringBuilder(@"\nr\" + Clients.Count); for (int i = 0; i < Clients.Count; i++) { Response.AppendFormat(@"\nick\{0}\uniquenick\{0}", Clients[i]["name"]); } Response.Append(@"\ndone\\final\"); Stream.SendAsync(Response.ToString()); } } catch { Stream.SendAsync(@"\error\\err\551\fatal\\errmsg\Unable to get any associated profiles.\id\1\final\"); } }