/// <summary> /// Requests the buddy. /// </summary> /// <param name="userQuery">The user query.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> internal bool RequestBuddy(string userQuery) { var clientByUsername = AzureEmulator.GetGame().GetClientManager().GetClientByUserName(userQuery); uint userId; bool blockForNewFriends; if (clientByUsername == null) { DataRow dataRow; using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("SELECT id, block_newfriends FROM users WHERE username = @query"); queryReactor.AddParameter("query", userQuery.ToLower()); dataRow = queryReactor.GetRow(); } if (dataRow == null) return false; userId = Convert.ToUInt32(dataRow["id"]); blockForNewFriends = AzureEmulator.EnumToBool(dataRow["block_newfriends"].ToString()); } else { Habbo currentUser = clientByUsername.GetHabbo(); userId = currentUser.Id; blockForNewFriends = currentUser.HasFriendRequestsDisabled; } var client = GetClient(); if (blockForNewFriends && client.GetHabbo().Rank < 4) { client .GetMessageHandler() .GetResponse() .Init(LibraryParser.OutgoingRequest("NotAcceptingRequestsMessageComposer")); client.GetMessageHandler().GetResponse().AppendInteger(39); client.GetMessageHandler().GetResponse().AppendInteger(3); client.GetMessageHandler().SendResponse(); return false; } if (RequestExists(userId)) { client.SendNotif("Je hebt al eerder een vriendenverzoek verstuurd."); return true; } using (var queryreactor2 = AzureEmulator.GetDatabaseManager().GetQueryReactor()) queryreactor2.RunFastQuery(string.Concat("REPLACE INTO messenger_requests (from_id,to_id) VALUES (", _userId, ",", userId, ")")); AzureEmulator.GetGame().GetQuestManager().ProgressUserQuest(client, QuestType.AddFriends, 0); Habbo fromUser = client.GetHabbo(); if (clientByUsername != null && clientByUsername.GetHabbo() != null && fromUser != null) { MessengerRequest messengerRequest = new MessengerRequest(userId, _userId, fromUser.UserName, fromUser.Look); clientByUsername.GetHabbo().GetMessenger().OnNewRequest(_userId, messengerRequest); var serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("ConsoleSendFriendRequestMessageComposer")); messengerRequest.Serialize(serverMessage); clientByUsername.SendMessage(serverMessage); } return true; }
/// <summary> /// Called when [new request]. /// </summary> /// <param name="friendId">The friend identifier.</param> internal void OnNewRequest(uint friendId, MessengerRequest friendRequest) { if (!Requests.ContainsKey(friendId)) Requests.Add(friendId, friendRequest); }