Esempio n. 1
0
        public static void HandleSendBuddies(GPCMClient client, Dictionary <string, string> recv)
        {
            // \bdy\<number of friends>\list\<array of profileids>\
            //TODO


            //total number of friends
            // we have to separate friends by productid,namespaceid,partnerid,gamename
            //because you will have different friends in different game



            if (client.BuddiesSent)
            {
                return;
            }

            /*Stream.SendAsync(
             *  @"\bdy\1\list\2,\final\");
             *
             * Stream.SendAsync(
             * //    @"\bm\100\f\2\msg\|s|0|ss|Offline\final\"
             * @"\bm\100\f\2\msg\Messaggio di prova|s|2|ss|Home|ls|locstr://Reversing the world...|\final\"
             * );*/

            client.Send(@"\bdy\1\list\13\final\");
            client.Send(@"\bm\100\f\13\msg\|s|0|ss|Offline\final\");
            client.Send(@"\bm\100\f\13\msg\1|signed|1");

            return;

            int[] pids       = SendBuddiesQuery.GetProfileidArray(recv);
            int   numBuddies = pids.Length;

            client.BuddiesSent = true;

            string sendingBuffer;
            string profileidArray = "";

            for (int i = 0; i < numBuddies; i++)
            {
                profileidArray += pids[i].ToString();
            }
            sendingBuffer = string.Format(@"\bdy\{0}\list\{1}\final\", numBuddies, profileidArray);
            client.Send(sendingBuffer);
        }
        /// <summary>
        /// Creates an account and use new account to login
        /// </summary>
        /// <param name="client">The client that sended the data</param>
        /// <param name="dict">The request that the stream sended</param>
        public static void NewUser(GPCMClient client, Dictionary <string, string> dict)
        {
            //Format the password for our database storage
            GPErrorCode error = IsRequestContainAllKeys(dict);

            //if there do not recieved right <key,value> pairs we send error
            if (error != GPErrorCode.NoError)
            {
                GameSpyUtils.SendGPError(client, error, "Error recieving request. Please check the input!");
                return;
            }

            //Check the nick and uniquenick is formated correct and uniquenick is existed in database
            string sendingBuffer;

            error = IsEmailNickUniquenickValied(dict);
            if (error != GPErrorCode.NoError)
            {
                sendingBuffer = string.Format(@"\nur\{0}\final\", (int)error);
                client.Send(sendingBuffer);
                return;
            }

            //if the request did not contain uniquenick and namespaceid we use our way to create it.
            PreProcessRequest(dict);
            //we get the userid in database. If no userid found according to email we create one
            //and store the new account into database.
            int profileid = CreateAccount(dict);

            if (profileid == -1)
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "Account is existed, please use another one.");
            }
            else
            {
                sendingBuffer = string.Format(@"\nur\0\pid\{0}\final\", profileid);
                client.Send(sendingBuffer);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Polls the connection, and checks for drops
 /// </summary>
 public static void SendKeepAlive(GPCMClient client)
 {
     if (client.PlayerInfo.LoginStatus == LoginStatus.Completed)
     {
         // Try and send a Keep-Alive
         try
         {
             client.Send(@"\ka\\final\");
         }
         catch
         {
             client.DisconnectByReason(DisconnectReason.KeepAliveFailed);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// update the uniquenick
        /// </summary>
        /// <param name="client"></param>
        /// <param name="dict"></param>
        public static void RegisterNick(GPCMClient client, Dictionary <string, string> dict)
        {
            GPErrorCode error = IsContainAllKeys(dict);

            if (error != GPErrorCode.NoError)
            {
                GameSpyUtils.SendGPError(client, error, "Parsing error");
                return;
            }
            string sendingBuffer;

            try
            {
                RegisterNickQuery.UpdateUniquenick(dict);
                sendingBuffer = @"\rn\final\";
                client.Send(sendingBuffer);
            }
            catch (Exception e)
            {
                LogWriter.Log.WriteException(e);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This method verifies the login information sent by
        /// the client, and returns encrypted data for the client
        /// to verify as well
        /// </summary>
        public static void ProcessLogin(GPCMClient client, Dictionary <string, string> recv, GPCMConnectionUpdate OnSuccessfulLogin, GPCMStatusChanged OnStatusChanged)
        {
            uint partnerID = 0;

            // Make sure we have all the required data to process this login
            //if (!recv.ContainsKey("challenge") || !recv.ContainsKey("response"))
            //{
            //    GameSpyUtils.SendGPError(client, GPErrorCode.General, "Invalid response received from the client!");
            //    client.DisconnectByReason(DisconnectReason.InvalidLoginQuery);
            //    return;
            //}
            if (IsContainAllKeys(recv) != GPErrorCode.NoError)
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.General, "Invalid response received from the client!");
                client.DisconnectByReason(DisconnectReason.InvalidLoginQuery);
                return;
            }


            // Parse the partnerid, required since it changes the challenge for Unique nick and User login
            ParseRequestToPlayerInfo(client, recv, ref partnerID);


            // Dispose connection after use
            try
            {
                // Try and fetch the user from the database

                Dictionary <string, object> queryResult;

                try
                {
                    if (client.PlayerInfo.PlayerUniqueNick.Length > 0)
                    {
                        queryResult = LoginQuery.GetUserFromUniqueNick(recv);
                    }
                    else if (client.PlayerInfo.PlayerAuthToken.Length > 0)
                    {
                        //TODO! Add the database entry
                        GameSpyUtils.SendGPError(client, GPErrorCode.General, "AuthToken is not supported yet");
                        return;
                    }
                    else
                    {
                        queryResult = LoginQuery.GetUserFromNickAndEmail(recv);
                    }
                }
                catch (Exception ex)
                {
                    LogWriter.Log.WriteException(ex);
                    GameSpyUtils.SendGPError(client, GPErrorCode.DatabaseError, "This request cannot be processed because of a database error.");
                    return;
                }

                //if no match found we disconnect the game
                if (queryResult == null)
                {
                    if (client.PlayerInfo.PlayerUniqueNick.Length > 0)
                    {
                        GameSpyUtils.SendGPError(client, GPErrorCode.LoginBadUniquenick, "The uniquenick provided is incorrect!");
                    }
                    else
                    {
                        GameSpyUtils.SendGPError(client, GPErrorCode.LoginBadUniquenick, "The information provided is incorrect!");
                    }
                    client.DisconnectByReason(DisconnectReason.InvalidUsername);
                    return;
                }

                // Check if user is banned
                string           msg;
                DisconnectReason reason;
                GPErrorCode      error = CheckUsersAccountAvailability(queryResult, out msg, out reason);
                if (error != GPErrorCode.NoError)
                {
                    GameSpyUtils.SendGPError(client, error, msg);
                    client.DisconnectByReason(reason);
                    return;
                }

                // we finally set the player variables and return challengeData
                string challengeData = SetPlayerInfo(client, queryResult, recv);
                string sendingBuffer;
                // Use the GenerateProof method to compare with the "response" value. This validates the given password
                if (recv["response"] == GenerateProof(recv["challenge"], client.ServerChallengeKey, challengeData, client.PlayerInfo.PlayerAuthToken.Length > 0 ? 0 : partnerID, client.PlayerInfo))
                {
                    // Create session key
                    client.SessionKey = Crc.ComputeChecksum(client.PlayerInfo.PlayerUniqueNick);

                    //actually we should store sesskey in database at namespace table, when we want someone's profile we just
                    //access to the sesskey to find the uniquenick for particular game
                    LoginQuery.UpdateSessionKey(recv, client.SessionKey, client.PlayerInfo);

                    // Password is correct
                    sendingBuffer = string.Format(@"\lc\2\sesskey\{0}\proof\{1}\userid\{2}\profileid\{2}\uniquenick\{3}\lt\{4}__\id\1\final\",
                                                  client.SessionKey,
                                                  GenerateProof(client.ServerChallengeKey, recv["challenge"], challengeData, client.PlayerInfo.PlayerAuthToken.Length > 0 ? 0 : partnerID, client.PlayerInfo), // Do this again, Params are reversed!
                                                  client.PlayerInfo.PlayerId,
                                                  client.PlayerInfo.PlayerUniqueNick,
                                                  // Generate LT whatever that is (some sort of random string, 22 chars long)
                                                  GameSpyLib.Common.Random.GenerateRandomString(22, GameSpyLib.Common.Random.StringType.Hex)
                                                  );
                    //Send response to client
                    client.Send(sendingBuffer);
                    // Log Incoming Connections
                    //LogWriter.Log.Write(LogLevel.Info, "{0,-8} [Login] {1} - {2} - {3}", client.ServerName, client.PlayerInfo.PlayerNick, client.PlayerInfo.PlayerId, RemoteEndPoint);
                    //string statusString = string.Format(" [Login Success!] Nick:{0} - Profileid:{1} - IP:{2}", client.PlayerInfo.PlayerNick, client.PlayerInfo.PlayerId, client.RemoteEndPoint);
                    client.StatusToLog("Login Success", client.PlayerInfo.PlayerNick, client.PlayerInfo.PlayerId, client.RemoteEndPoint, null);
                    // Update status last, and call success login
                    client.PlayerInfo.LoginStatus          = LoginStatus.Completed;
                    client.PlayerInfo.PlayerStatus         = PlayerStatus.Online;
                    client.PlayerInfo.PlayerStatusString   = "Online";
                    client.PlayerInfo.PlayerStatusLocation = "";
                    client.CompletedLoginProcess           = true;

                    OnSuccessfulLogin?.Invoke(client);
                    OnStatusChanged?.Invoke(client);
                    SendBuddiesHandler.HandleSendBuddies(client, recv);
                }
                else
                {
                    // Log Incoming Connection
                    string statusString = string.Format(@"[Login Failed!] Nick:{0} - Profileid:{1} - IP:{2}", client.PlayerInfo.PlayerNick, client.PlayerInfo.PlayerId, client.RemoteEndPoint);
                    client.ToLog(LogLevel.Info, statusString);
                    // Password is incorrect with database value.
                    client.Send(@"\error\\err\260\fatal\\errmsg\The password provided is incorrect.\id\1\final\");
                    client.DisconnectByReason(DisconnectReason.InvalidPassword);
                }
            }
            catch (Exception ex)
            {
                LogWriter.Log.Write(ex.ToString(), LogLevel.Error);
                client.DisconnectByReason(DisconnectReason.GeneralError);
                return;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// This method is called when the client requests for the Account profile
        /// </summary>
        public static void SendProfile(GPCMClient client, Dictionary <string, string> recv)
        {
            //TODO

            // \getprofile\\sesskey\19150\profileid\2\id\2\final\
            //profileid is

            if (!recv.ContainsKey("profileid"))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }

            uint targetPID, messID, sesskey;

            if (!uint.TryParse(recv["profileid"], out targetPID))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }

            if (!uint.TryParse(recv["id"], out messID))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }
            if (!uint.TryParse(recv["sesskey"], out sesskey))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }

            string datatoSend = @"\pi\profileid\" + targetPID + @"\mp\4";

            // If the client want to access the public information
            // of another client
            if (targetPID != client.PlayerInfo.PlayerId)
            {
                GPCMPlayerInfo playerInfo = GetProfileQuery.GetProfileInfo(targetPID);
                if (playerInfo == null)
                {
                    GameSpyUtils.SendGPError(client, 4, "Unable to get profile information.");
                    return;
                }

                datatoSend = string.Format(datatoSend + @"\nick\{0}\uniquenick\{1}\id\{2}", playerInfo.PlayerNick, playerInfo.PlayerUniqueNick, messID);

                if (playerInfo.PlayerEmail.Length > 0)
                {
                    datatoSend += @"\email\" + playerInfo.PlayerEmail;
                }

                if (playerInfo.PlayerLastName.Length > 0)
                {
                    datatoSend += @"\lastname\" + playerInfo.PlayerLastName;
                }

                if (playerInfo.PlayerFirstName.Length > 0)
                {
                    datatoSend += @"\firstname\" + playerInfo.PlayerFirstName;
                }

                if (playerInfo.PlayerICQ != 0)
                {
                    datatoSend += @"\icquin\" + playerInfo.PlayerICQ;
                }

                if (playerInfo.PlayerHomepage.Length > 0)
                {
                    datatoSend += @"\homepage\" + playerInfo.PlayerHomepage;
                }

                if (playerInfo.PlayerPicture != 0)
                {
                    datatoSend += @"\pic\" + playerInfo.PlayerPicture;
                }

                if (playerInfo.PlayerAim.Length > 0)
                {
                    datatoSend += @"\aim\" + playerInfo.PlayerAim;
                }

                if (playerInfo.PlayerOccupation != 0)
                {
                    datatoSend += @"\occ\" + playerInfo.PlayerOccupation;
                }

                if (playerInfo.PlayerZIPCode.Length > 0)
                {
                    datatoSend += @"\zipcode\" + playerInfo.PlayerZIPCode;
                }

                if (playerInfo.PlayerCountryCode.Length > 0)
                {
                    datatoSend += @"\countrycode\" + playerInfo.PlayerCountryCode;
                }

                if (playerInfo.PlayerBirthday > 0 && playerInfo.PlayerBirthmonth > 0 && playerInfo.PlayerBirthyear > 0)
                {
                    datatoSend += @"\birthday\" + (uint)((playerInfo.PlayerBirthday << 24) | (playerInfo.PlayerBirthmonth << 16) | playerInfo.PlayerBirthyear);
                }

                if (playerInfo.PlayerLocation.Length > 0)
                {
                    datatoSend += @"\loc\" + playerInfo.PlayerLocation;
                }

                if (playerInfo.PlayerSex != PlayerSexType.PAT)
                {
                    if (playerInfo.PlayerSex == PlayerSexType.FEMALE)
                    {
                        datatoSend += @"\sex\1";
                    }
                    else if (playerInfo.PlayerSex == PlayerSexType.MALE)
                    {
                        datatoSend += @"\sex\0";
                    }
                }

                if (playerInfo.PlayerLatitude != 0.0f)
                {
                    datatoSend += @"\lat\" + playerInfo.PlayerLatitude;
                }

                if (playerInfo.PlayerLongitude != 0.0f)
                {
                    datatoSend += @"\lon\" + playerInfo.PlayerLongitude;
                }

                if (playerInfo.PlayerIncomeID != 0)
                {
                    datatoSend += @"\inc\" + playerInfo.PlayerIncomeID;
                }

                if (playerInfo.PlayerIndustryID != 0)
                {
                    datatoSend += @"\ind\" + playerInfo.PlayerIndustryID;
                }

                if (playerInfo.PlayerMarried != 0)
                {
                    datatoSend += @"\mar\" + playerInfo.PlayerMarried;
                }

                if (playerInfo.PlayerChildCount != 0)
                {
                    datatoSend += @"\chc\" + playerInfo.PlayerChildCount;
                }

                if (playerInfo.PlayerInterests != 0)
                {
                    datatoSend += @"\i1\" + playerInfo.PlayerInterests;
                }

                if (playerInfo.PlayerOwnership != 0)
                {
                    datatoSend += @"\o1\" + playerInfo.PlayerOwnership;
                }

                if (playerInfo.PlayerConnectionType != 0)
                {
                    datatoSend += @"\conn\" + playerInfo.PlayerConnectionType;
                }

                // SUPER NOTE: Please check the Signature of the PID, otherwise when it will be compared with other peers, it will break everything (See gpiPeer.c @ peerSig)
                datatoSend += @"\sig\" + GameSpyLib.Common.Random.GenerateRandomString(33, GameSpyLib.Common.Random.StringType.Hex) + @"\final\";
            }
            else
            {
                // Since this is our profile, we have to see ALL informations that we can edit. This means that we don't need to check the public masks for sending
                // the data

                datatoSend = string.Format(datatoSend + @"\nick\{0}\uniquenick\{1}\email\{2}\id\{3}\pmask\{4}",
                                           client.PlayerInfo.PlayerNick,
                                           client.PlayerInfo.PlayerUniqueNick,
                                           client.PlayerInfo.PlayerEmail,
                                           /*(ProfileSent ? "5" : "2")*/ messID,
                                           client.PlayerInfo.PlayerPublicMask
                                           );

                if (client.PlayerInfo.PlayerLastName.Length > 0)
                {
                    datatoSend += @"\lastname\" + client.PlayerInfo.PlayerLastName;
                }

                if (client.PlayerInfo.PlayerFirstName.Length > 0)
                {
                    datatoSend += @"\firstname\" + client.PlayerInfo.PlayerFirstName;
                }

                if (client.PlayerInfo.PlayerICQ != 0)
                {
                    datatoSend += @"\icquin\" + client.PlayerInfo.PlayerICQ;
                }

                if (client.PlayerInfo.PlayerHomepage.Length > 0)
                {
                    datatoSend += @"\homepage\" + client.PlayerInfo.PlayerHomepage;
                }

                if (client.PlayerInfo.PlayerPicture != 0)
                {
                    datatoSend += @"\pic\" + client.PlayerInfo.PlayerPicture;
                }

                if (client.PlayerInfo.PlayerAim.Length > 0)
                {
                    datatoSend += @"\aim\" + client.PlayerInfo.PlayerAim;
                }

                if (client.PlayerInfo.PlayerOccupation != 0)
                {
                    datatoSend += @"\occ\" + client.PlayerInfo.PlayerOccupation;
                }

                if (client.PlayerInfo.PlayerZIPCode.Length > 0)
                {
                    datatoSend += @"\zipcode\" + client.PlayerInfo.PlayerZIPCode;
                }

                if (client.PlayerInfo.PlayerCountryCode.Length > 0)
                {
                    datatoSend += @"\countrycode\" + client.PlayerInfo.PlayerCountryCode;
                }

                if (client.PlayerInfo.PlayerBirthday > 0 && client.PlayerInfo.PlayerBirthmonth > 0 && client.PlayerInfo.PlayerBirthyear > 0)
                {
                    datatoSend += @"\birthday\" + (uint)((client.PlayerInfo.PlayerBirthday << 24) | (client.PlayerInfo.PlayerBirthmonth << 16) | client.PlayerInfo.PlayerBirthyear);
                }

                if (client.PlayerInfo.PlayerLocation.Length > 0)
                {
                    datatoSend += @"\loc\" + client.PlayerInfo.PlayerLocation;
                }

                if (client.PlayerInfo.PlayerSex == PlayerSexType.FEMALE)
                {
                    datatoSend += @"\sex\1";
                }
                else if (client.PlayerInfo.PlayerSex == PlayerSexType.MALE)
                {
                    datatoSend += @"\sex\0";
                }

                if (client.PlayerInfo.PlayerLatitude != 0.0f)
                {
                    datatoSend += @"\lat\" + client.PlayerInfo.PlayerLatitude;
                }

                if (client.PlayerInfo.PlayerLongitude != 0.0f)
                {
                    datatoSend += @"\lon\" + client.PlayerInfo.PlayerLongitude;
                }

                if (client.PlayerInfo.PlayerIncomeID != 0)
                {
                    datatoSend += @"\inc\" + client.PlayerInfo.PlayerIncomeID;
                }

                if (client.PlayerInfo.PlayerIndustryID != 0)
                {
                    datatoSend += @"\ind\" + client.PlayerInfo.PlayerIndustryID;
                }

                if (client.PlayerInfo.PlayerMarried != 0)
                {
                    datatoSend += @"\mar\" + client.PlayerInfo.PlayerMarried;
                }

                if (client.PlayerInfo.PlayerChildCount != 0)
                {
                    datatoSend += @"\chc\" + client.PlayerInfo.PlayerChildCount;
                }

                if (client.PlayerInfo.PlayerInterests != 0)
                {
                    datatoSend += @"\i1\" + client.PlayerInfo.PlayerInterests;
                }

                if (client.PlayerInfo.PlayerOwnership != 0)
                {
                    datatoSend += @"\o1\" + client.PlayerInfo.PlayerOwnership;
                }

                if (client.PlayerInfo.PlayerConnectionType != 0)
                {
                    datatoSend += @"\conn\" + client.PlayerInfo.PlayerConnectionType;
                }

                // SUPER NOTE: Please check the Signature of the PID, otherwise when it will be compared with other peers, it will break everything (See gpiPeer.c @ peerSig)
                datatoSend += @"\sig\" + GameSpyLib.Common.Random.GenerateRandomString(33, GameSpyLib.Common.Random.StringType.Hex) + @"\final\";

                // Set that we send the profile initially
                if (!client.ProfileSent)
                {
                    client.ProfileSent = true;
                }
            }

            client.Send(datatoSend);
        }