Beispiel #1
0
        /// <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(DisconnectReason.CreateFailedUsernameExists);
                        return;
                    }

                    // We need to decode the Gamespy specific encoding for the password
                    string Password = GamespyUtils.DecodePassword(Recv["passwordenc"]);
                    string Cc       = (RemoteEndPoint.AddressFamily == AddressFamily.InterNetwork)
                        ? GeoIP.GetCountryCode(RemoteEndPoint.Address)
                        : "US";

                    // 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(DisconnectReason.CreateFailedDatabaseError);
                        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\");
                    Program.ErrorLog.Write("ERROR: [GpcmClient.CreateNewUser] An error occured while trying to create a new User account :: " + e.Message);
                }

                Disconnect(DisconnectReason.GeneralError);
                return;
            }
        }
Beispiel #2
0
        /// <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
            {
                // Check to see if user exists
                if (DatabaseUtility.UserExists(databaseDriver, Recv["nick"]))
                {
                    Stream.SendAsync(@"\error\\err\516\fatal\\errmsg\This account name is already in use!\id\1\final\");
                    Disconnect(DisconnectReason.CreateFailedUsernameExists);
                    return;
                }

                // We need to decode the Gamespy specific encoding for the password
                string Password = GamespyUtils.DecodePassword(Recv["passwordenc"]);
                string Cc       = (RemoteEndPoint.AddressFamily == AddressFamily.InterNetwork)
                                  //? GeoIP.GetCountryCode(RemoteEndPoint.Address)
                                  //: "US";
                    ? "US" : "US";

                // Attempt to create account. If Pid is 0, then we couldnt create the account. TODO: Handle Unique Nickname
                if ((PlayerId = DatabaseUtility.CreateUser(databaseDriver, Recv["nick"], Password, Recv["email"], Cc, Recv["nick"])) == 0)
                {
                    PresenceServer.SendError(Stream, 516, "An error oncurred while creating the account!");
                    Disconnect(DisconnectReason.CreateFailedDatabaseError);
                    return;
                }

                Stream.SendAsync(@"\nur\\userid\{0}\profileid\{0}\id\1\final\", PlayerId);
            }
            catch (Exception e)
            {
                // Check for invalid query params
                if (e is KeyNotFoundException)
                {
                    PresenceServer.SendError(Stream, 516, "Invalid response received from the client!");
                }
                else
                {
                    PresenceServer.SendError(Stream, 516, "An error oncurred while creating the account!");
                    LogWriter.Log.Write("An error occured while trying to create a new User account :: " + e.Message, LogLevel.Error);
                }

                Disconnect(DisconnectReason.GeneralError);
                return;
            }
        }
Beispiel #3
0
        /// <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 soldiers that match this email and password
                using (GamespyDatabase Db = new GamespyDatabase())
                {
                    var           Clients  = Db.GetUsersByEmailPass(recvData["email"], password);
                    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\");
            }
        }
Beispiel #4
0
        private void RetriveNicknames(TCPStream stream, Dictionary <string, string> dict)
        {
            string password       = "";
            bool   sendUniqueNick = false;

            if (!dict.ContainsKey("email"))
            {
                SendErrorAndFreeStream(stream, 1, "There was an error parsing an incoming request.");
                return;
            }

            // First, we try to receive an encoded password
            if (!dict.ContainsKey("passenc"))
            {
                // If the encoded password is not sended, we try receving the password in plain text
                if (!dict.ContainsKey("pass"))
                {
                    // No password is specified, we cannot continue
                    SendErrorAndFreeStream(stream, 1, "There was an error parsing an incoming request.");
                    return;
                }
                else
                {
                    // Store the plain text password
                    password = dict["pass"];
                }
            }
            else
            {
                // Store the decrypted password
                password = GamespyUtils.DecodePassword(dict["passenc"]);
            }

            password = StringExtensions.GetMD5Hash(password);

            sendUniqueNick = dict.ContainsKey("gamename");

            List <Dictionary <string, object> > queryResult = null;

            try
            {
                queryResult = databaseDriver.Query("SELECT profiles.nick, profiles.uniquenick FROM profiles INNER JOIN users ON profiles.userid=users.userid WHERE LOWER(users.email)=@P0 AND LOWER(users.password)=@P1", dict["email"].ToLowerInvariant(), password.ToLowerInvariant());
            }
            catch (Exception ex)
            {
                LogWriter.Log.Write(ex.Message, LogLevel.Error);
                SendErrorAndFreeStream(stream, 4, "This request cannot be processed because of a database error.");
                return;
            }

            if (queryResult.Count < 1)
            {
                stream.SendAsync(@"\nr\ndone\final\");
                return;
            }

            // We will recycle the "password" variable by storing the response
            // that we have to send to the stream. This is done for save memory space
            // so we don't have to declare a new variable.
            password = @"\nr\";

            foreach (Dictionary <string, object> row in queryResult)
            {
                password += @"\nick\";
                password += row["nick"];

                if (sendUniqueNick)
                {
                    password += @"\uniquenick\";
                    password += row["uniquenick"];
                }
            }

            password += @"\ndone\final\";
            stream.SendAsync(password);

            /* Legacy C++ code to reimpliment
             * bool PSServer::OnSendNicks(mdk_socket stream, const char *buf, int)
             * {
             *  std::string email = "", pass = "", gamename = "", str = "";
             *  bool bSendUnique = false;
             *  size_t i = 0;
             *  CResultSet *result = NULL;
             *
             *  // Get data from buffer
             *
             *  if (!get_gs_data(buf, email, "email"))
             *      return false;
             *
             *  if (get_gs_data(buf, pass, "passenc"))
             *  {
             *      // Uncrypt the password
             *      gs_pass_decode(pass);
             *  }
             *  else
             *  {
             *      if (!get_gs_data(buf, pass, "pass"))
             *          return false;
             *  }
             *
             *  if (get_gs_data(buf, gamename, "gamename"))
             *      bSendUnique = true;
             *
             *  // Create the query and execute it
             *  str = "SELECT profiles.nick, profiles.uniquenick FROM profiles INNER "
             *      "JOIN users ON profiles.userid=users.userid WHERE users.email='";
             *  if (!mdk_escape_query_string(m_lpDatabase, email))
             *      return false;
             *
             *  str += email;
             *  str += "' AND password='******'";
             *
             *  result = new CResultSet();
             *
             *  if (!result->ExecuteQuery(m_lpDatabase, str))
             *  {
             *      delete result;
             *
             *      WriteTCP(stream, "\\nr\\\\ndone\\final\\");
             *      return false;
             *  }
             *
             *  if (!result->GotoFirstRow())
             *  {
             *      delete result;
             *
             *      WriteTCP(stream, "\\nr\\\\ndone\\final\\");
             *      return false;
             *
             *  }
             *
             *  str = "\\nr\\" + std::to_string(result->GetTotalRows());
             *
             *  // Get all the nicks and store them
             *  do
             *  {
             *      str += "\\nick\\";
             *      str += result->GetStringFromRow(0);
             *
             *      if (bSendUnique)
             *      {
             *          str += "\\uniquenick\\";
             *          str += result->GetStringFromRow(1);
             *      }
             *  } while(result->GotoNextRow());
             *
             *  str += "\\ndone\\final\\";
             *
             *  // Send to the socket
             *  WriteTCP(stream, str);
             *
             *  delete result;
             *
             *  return true;
             * }*/
        }