/// <summary> /// Refreshes the session user's club status. /// </summary> public void refreshClubStatus() { if (this.isHoldingUser) { serverMessage Message = new serverMessage(7); // "@G" Message.appendClosedValue("club_habbo"); Message.appendWired(this.User.clubDaysLeft); Message.appendWired(this.User.clubMonthsExpired); Message.appendWired(this.User.clubMonthsLeft); Message.appendWired(true); // Hide/shows 'days left' label this.gameConnection.sendMessage(Message); } }
private void operateTeleporter(uint sessionID, int itemID) { floorItem pItem = this.getFloorItem(itemID); if (pItem != null && pItem.Definition.Behaviour.isTeleporter) // Valid item { Thread.Sleep(550); // Wait for room worker thread to locate user into teleporter roomUser pUser = this.getRoomUser(sessionID); if (pUser != null && pUser.X == pItem.X && pUser.Y == pItem.Y) // In teleporter { int roomID = ObjectTree.Game.Items.getTeleporterRoomID(pItem.teleporterID); if (roomID == 0) { return; } pUser.Clamped = true; this.broadcoastTeleportActivity(pItem.ID, pUser.Session.User.Username, true); this.gridUnit[pItem.X, pItem.Y] = false; // Unblock teleporter if (roomID == this.roomID) { Thread.Sleep(500); floorItem pTeleporter2 = this.getFloorItem(pItem.teleporterID); pUser.X = pTeleporter2.X; pUser.Y = pTeleporter2.Y; pUser.Z = pTeleporter2.Z; pUser.rotationHead = pTeleporter2.Rotation; pUser.rotationBody = pTeleporter2.Rotation; this.gridUnit[pUser.X, pUser.Y] = true; // Block teleporter 2 this.broadcoastTeleportActivity(pTeleporter2.ID, pUser.Session.User.Username, false); pUser.Clamped = false; pUser.requiresUpdate = true; } else { pUser.Session.authenticatedFlat = roomID; pUser.Session.authenticatedTeleporter = pItem.teleporterID; serverMessage Message = new serverMessage(62); // "@~" Message.appendWired(pItem.teleporterID); Message.appendWired(roomID); pUser.Session.gameConnection.sendMessage(Message); } } } }
/// <summary> /// 56 - "@x" /// </summary> public void WHISPER() { roomUser Me = Session.roomInstance.getRoomUser(Session.ID); if (!Me.isMuted) { string whisperBody = Request.getParameter(0); string receiverName = whisperBody.Substring(0, whisperBody.IndexOf(' ')); string Text = whisperBody.Substring(receiverName.Length + 1); stringFunctions.filterVulnerableStuff(ref Text, true); serverMessage Whisper = new serverMessage(25); // "@Y" Whisper.appendWired(Me.ID); Whisper.appendClosedValue(Text); Session.gameConnection.sendMessage(Whisper); if (receiverName.Length > 0 && receiverName != Session.User.Username) { roomUser Receiver = Session.roomInstance.getRoomUser(receiverName); if (Receiver != null) { Receiver.Session.gameConnection.sendMessage(Whisper); } ObjectTree.Game.Moderation.addChatMessageToLogStack(Session.ID, Session.User.ID, Session.roomID, Receiver.Session.User.ID, chatType.whisper, ref Text); } } }
public void sendShout(int sourceID, byte sourceX, byte sourceY, string Text) { serverMessage Message = new serverMessage(26); // "@Z" Message.appendWired(sourceID); Message.appendClosedValue(Text); sendMessage(Message); // TODO: head rotation }
/// <summary> /// Refreshes the badges for this session user and re-builds the badges message. (229, "Ce") /// </summary> public void refreshBadgeList() { if (this.isHoldingUser) { List <string> myBadges = Engine.Game.Roles.getDefaultBadgesForRole(this.User.Role); myBadges.Remove("HC1"); Engine.Game.Users.addPrivateBadgesToList(this.User.ID, this.User.Role, ref myBadges); if (this.User.hasClub) // Regular club member { myBadges.Add("HC1"); // TODO: make this configurable } if (this.User.hasGoldClub) // Gold club member { myBadges.Add("HC2"); // TODO: make this configurable } if (!myBadges.Contains(this.User.Badge)) // Set badge not valid anymore { this.User.Badge = ""; } serverMessage Message = new serverMessage(229); // "Ce" Message.appendWired(myBadges.Count); int badgeSlot = 0; int slotCounter = 0; foreach (string lBadge in myBadges) { Message.appendClosedValue(lBadge); if (lBadge == this.User.Badge) // Current badge, set slot { badgeSlot = slotCounter; } slotCounter++; } Message.appendWired(badgeSlot); Message.appendWired((this.User.Badge.Length > 0)); this.gameConnection.sendMessage(Message); } }
/// <summary> /// Only works if the session user is in a room. If so, then a whisper with a given message is sent to the user only. /// </summary> /// <param name="Message">The text message to whisper to the user.</param> public void castWhisper(string sMessage) { if (this.inRoom) { serverMessage Message = new serverMessage(25); // "@Y" Message.appendWired(this.roomInstance.getSessionRoomUnitID(this.ID)); Message.appendClosedValue(sMessage); this.gameConnection.sendMessage(Message); } }
/// <summary> /// Updates the badge status of a given room user in the room. /// </summary> /// <param name="sessionID">The session ID of the session where the target room user belongs to.</param> public void updateUserBadge(uint sessionID) { serverMessage Notify = new serverMessage(228); // "Cd" roomUser rUser = roomUsers[sessionID]; Notify.appendWired(rUser.ID); if (rUser.Session.User.Badge.Length > 0) { Notify.appendClosedValue(rUser.Session.User.Badge); } sendMessage(Notify); }
public void removeBuddy(int userID, int buddyID) { Database Database = new Database(false, false); Database.addParameterWithValue("userid", userID); Database.addParameterWithValue("buddyid", buddyID); Database.Open(); if (Database.Ready) { Database.runQuery("DELETE FROM messenger_buddylist WHERE (userid = @userid AND buddyid = @buddyid) OR (userid = @buddyid AND buddyid = @userid) AND accepted = '1' LIMIT 1"); Database.runQuery("DELETE FROM messenger_messages WHERE (receiverid = @userid AND senderid = @buddyid) OR (receiverid = @buddyid AND senderid = @userid)"); // Delete messages between users Database.Close(); } if (ObjectTree.Game.Users.userIsLoggedIn(buddyID)) // Victim is online { serverMessage Message = new serverMessage(138); // "BJ" Message.appendWired(1); Message.appendWired(userID); ObjectTree.Game.Users.trySendGameMessage(buddyID, Message); } }
public void sendTalk(int sourceID, byte sourceX, byte sourceY, string Text) { string sFullMessage = ""; serverMessage Message = new serverMessage(24); // "@X" Message.appendWired(sourceID); Message.appendClosedValue(Text); sFullMessage = Message.ToString(); Message = null; lock (roomUsers) { foreach (roomUser lRoomUser in roomUsers.Values) { int distX = Math.Abs(sourceX - lRoomUser.X) - 1; int distY = Math.Abs(sourceY - lRoomUser.Y) - 1; if (distX < 9 && distY < 9) // User can hear { if (distX <= 6 && distY <= 6) // User can hear full message { lRoomUser.Session.gameConnection.sendMessage(sFullMessage); } else // User can hear garbled message { Message = new serverMessage(24); // "@X" Message.appendWired(sourceID); int garbleIntensity = distX; if (distY < distX) { garbleIntensity = distY; } garbleIntensity -= 4; string garbledText = Text; stringFunctions.garbleText(ref garbledText, garbleIntensity); Message.appendClosedValue(garbledText); lRoomUser.Session.gameConnection.sendMessage(Message); Message = null; } } } } }
/// <summary> /// Writes a buddy request from a given user to another user into the database, and notifies the receiver with the new request if it's online. /// </summary> /// <param name="User">The userInformation object of the user that sends the request.</param> /// <param name="userID2">The database ID of the receiving user.</param> public void requestBuddy(userInformation User, int userID2) { Database Database = new Database(false, true); Database.addParameterWithValue("userid", User.ID); Database.addParameterWithValue("userid2", userID2); Database.Open(); Database.runQuery("INSERT INTO messenger_buddylist(userid,buddyid) VALUES (@userid,@userid2)"); if (ObjectTree.Game.Users.userIsLoggedIn(userID2)) // Receiver is online { serverMessage Message = new serverMessage(132); // "BD" Message.appendWired(User.ID); Message.appendClosedValue(User.Username); ObjectTree.Game.Users.trySendGameMessage(userID2, Message); } }
private void _launchBird(int[] receiverIDs, messengerMessage pMessage) { Database Database = new Database(false, false); Database.addParameterWithValue("senderid", pMessage.senderID); Database.addParameterWithValue("sent", pMessage.Sent); Database.addParameterWithValue("body", pMessage.Body); Database.Open(); if (Database.Ready) { //DateTime now = DateTime.Now; //Woodpecker.Core.Logging.Log("Start: " + now.ToString("hh:mm:ss:fff")); foreach (int receiverID in receiverIDs) { if (Engine.Game.Users.userIsLoggedIn(receiverID)) // Receiver is logged in, retrieve the next message ID, write the message in the database & send it to the receiver { int messageID = Database.getInteger("SELECT MAX(messageid) + 1 FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1"); Database.runQuery("INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) VALUES ('" + receiverID + "','" + messageID + "',@senderid,@sent,@body)"); serverMessage Message = new serverMessage(134); // "BF" Message.appendWired(1); pMessage.ID = messageID; Message.Append(pMessage.ToString()); Engine.Game.Users.trySendGameMessage(receiverID, Message); } else // Receiver is not online, no need for getting our hands on the next message ID etc { Database.runQuery( "INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) " + "SELECT " + "'" + receiverID + "'," + "(MAX(messageid) + 1)," + "@senderid," + "@sent," + "@body " + "FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1"); } } //now = DateTime.Now; //Woodpecker.Core.Logging.Log("Stop: " + now.ToString("hh:mm:ss:fff")); Database.Close(); } }
private void operateTeleporter(uint sessionID, int itemID) { floorItem pItem = this.getFloorItem(itemID); if (pItem != null && pItem.Definition.Behaviour.isTeleporter) // Valid item { Thread.Sleep(550); // Wait for room worker thread to locate user into teleporter roomUser pUser = this.getRoomUser(sessionID); if (pUser != null && pUser.X == pItem.X && pUser.Y == pItem.Y) // In teleporter { int roomID = ObjectTree.Game.Items.getTeleporterRoomID(pItem.teleporterID); if (roomID == 0) return; pUser.Clamped = true; this.broadcoastTeleportActivity(pItem.ID, pUser.Session.User.Username, true); this.gridUnit[pItem.X, pItem.Y] = false; // Unblock teleporter if (roomID == this.roomID) { Thread.Sleep(500); floorItem pTeleporter2 = this.getFloorItem(pItem.teleporterID); pUser.X = pTeleporter2.X; pUser.Y = pTeleporter2.Y; pUser.Z = pTeleporter2.Z; pUser.rotationHead = pTeleporter2.Rotation; pUser.rotationBody = pTeleporter2.Rotation; this.gridUnit[pUser.X, pUser.Y] = true; // Block teleporter 2 this.broadcoastTeleportActivity(pTeleporter2.ID, pUser.Session.User.Username, false); pUser.Clamped = false; pUser.requiresUpdate = true; } else { pUser.Session.authenticatedFlat = roomID; pUser.Session.authenticatedTeleporter = pItem.teleporterID; serverMessage Message = new serverMessage(62); // "@~" Message.appendWired(pItem.teleporterID); Message.appendWired(roomID); pUser.Session.gameConnection.sendMessage(Message); } } } }
/// <summary> /// Handles a given remote request and returns a boolean that indicates if the request has been successfully handled. /// </summary> /// <param name="messageID">The ID of the request to process.</param> /// <param name="args">The string array with the request content.</param> public bool handleRequest(int messageID, string[] args) { try { switch (messageID) { #region System case 0: // Stop Woodpecker { Engine.Program.Stop(args[1]); return(true); } case 1: // Hotel alert { stringFunctions.filterVulnerableStuff(ref args[1], false); Engine.Game.Users.broadcastHotelAlert(args[1]); return(true); } case 2: // Offline in %x% minutes alert { int leftMinutes = 0; if (int.TryParse(args[1], out leftMinutes)) { serverMessage Message = new serverMessage(291); // "Dc" Message.appendWired(leftMinutes); Engine.Game.Users.broadcastMessage(Message); return(true); } } break; #endregion #region Moderation #region Single user events case 31: // Remote user alert { int userID = 0; if (int.TryParse(args[1], out userID)) { int targetUserID = 0; if (int.TryParse(args[2], out targetUserID)) { stringFunctions.filterVulnerableStuff(ref args[3], true); // Message stringFunctions.filterVulnerableStuff(ref args[4], true); // Extra info return(Engine.Game.Moderation.requestAlert(userID, targetUserID, args[3], args[4])); } } } break; case 32: // Remote user kick { int userID = 0; if (int.TryParse(args[1], out userID)) { int targetUserID = 0; if (int.TryParse(args[2], out targetUserID)) { stringFunctions.filterVulnerableStuff(ref args[3], true); // Message stringFunctions.filterVulnerableStuff(ref args[4], true); // Extra info return(Engine.Game.Moderation.requestKickFromRoom(userID, targetUserID, args[3], args[4])); } } } break; case 33: // Remote user ban { int userID = 0; if (int.TryParse(args[1], out userID)) { int targetUserID = 0; if (int.TryParse(args[2], out targetUserID)) { int Hours = 0; if (int.TryParse(args[3], out Hours)) { bool banIP = (args[4] == "1"); bool banMachine = (args[5] == "1"); stringFunctions.filterVulnerableStuff(ref args[6], true); stringFunctions.filterVulnerableStuff(ref args[7], true); return(Engine.Game.Moderation.requestBan(userID, targetUserID, Hours, banIP, banMachine, args[6], args[7])); } } } } break; #endregion #region Room instance events case 34: // Remote room alert { int userID = 0; if (int.TryParse(args[1], out userID)) { int roomID = 0; if (int.TryParse(args[2], out roomID)) { stringFunctions.filterVulnerableStuff(ref args[3], true); // Message stringFunctions.filterVulnerableStuff(ref args[4], true); // Extra info return(Engine.Game.Moderation.requestRoomAlert(userID, roomID, args[3], args[4])); } } } break; case 35: // Remote room kick { int userID = 0; if (int.TryParse(args[1], out userID)) { int roomID = 0; if (int.TryParse(args[2], out roomID)) { stringFunctions.filterVulnerableStuff(ref args[3], true); // Message stringFunctions.filterVulnerableStuff(ref args[4], true); // Extra info return(Engine.Game.Moderation.requestRoomKick(userID, roomID, args[3], args[4])); } } } break; #endregion #endregion } } catch { } Core.Logging.Log("Remote request handler: error ocurred, OR no remote request handler for " + messageID); return(false); // Failed! }
private void runRollers() { if (mRollerTimer > DateTime.Now.TimeOfDay.TotalSeconds && mRollerDay == DateTime.Today.DayOfYear) { return; } StringBuilder Updates = new StringBuilder(); List <int> movedRoomUnitIDs = new List <int>(); List <int> movedItemIDs = new List <int>(); try { foreach (floorItem lRoller in this.floorItems) { if (!lRoller.Definition.Behaviour.isRoller) { continue; // Not a roller item } #region General // Workout direction for roller byte nextX = lRoller.X; byte nextY = lRoller.Y; if (lRoller.Rotation == 0) { nextY--; } else if (lRoller.Rotation == 2) { nextX++; } else if (lRoller.Rotation == 4) { nextY++; } else if (lRoller.Rotation == 6) { nextX--; } if (!tileExists(nextX, nextY) || tileBlockedByRoomUnit(nextX, nextY)) { continue; // Can't roll off room map / on room unit } #endregion #region Get objects on current tile and verify roomUnit pUnit = this.getRoomUnitOnTile(lRoller.X, lRoller.Y); // Get room unit on this roller List <floorItem> pItems = new List <floorItem>(); foreach (floorItem lItem in this.getFloorItems(lRoller.X, lRoller.Y)) { if (!lItem.Definition.Behaviour.isRoller && !movedItemIDs.Contains(lItem.ID)) { pItems.Add(lItem); } } if (pUnit != null && (pUnit.Moves || movedRoomUnitIDs.Contains(pUnit.ID))) { pUnit = null; // Invalid room unit } if (pUnit == null && pItems.Count == 0) { continue; // No items on roller and no room unit aswell } #endregion // Get items on next tile and perform some checks bool nextTileIsRoller = false; bool canMoveItems = (this.gridState[nextX, nextY] == roomTileState.Free); bool canMoveUnit = canMoveItems; bool nextTileUnitInteractiveStance = false; foreach (floorItem lItem in this.getFloorItems(nextX, nextY)) { if (lItem.Definition.Behaviour.isRoller) { nextTileIsRoller = true; continue; } if (lItem.Definition.Behaviour.isSolid) { canMoveItems = false; canMoveUnit = false; if (lItem.Definition.Behaviour.isDoor) { if (lItem.customData == "O") // Door is open { canMoveUnit = true; // Can move unit in door } } } else if (pUnit != null && lItem.Definition.isInteractiveStance) { nextTileUnitInteractiveStance = true; if (!nextTileIsRoller) { canMoveUnit = true; } } } if (!canMoveItems) // Can't move items { if (!canMoveUnit) // Can't move unit aswell { continue; // Can't run this roller } pItems.Clear(); // Clear items to move } #region Generate notification and move objects serverMessage eventNotification = new serverMessage(230); // "Cf" eventNotification.appendWired(lRoller.X); eventNotification.appendWired(lRoller.Y); eventNotification.appendWired(nextX); eventNotification.appendWired(nextY); eventNotification.appendWired(pItems.Count); foreach (floorItem lItem in pItems) { float nextZ = lItem.Z; if (!nextTileIsRoller) { nextZ -= lRoller.Definition.topHeight; } eventNotification.appendWired(lItem.ID); eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(lItem.Z)); eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(nextZ)); lItem.X = nextX; lItem.Y = nextY; lItem.Z = nextZ; lItem.requiresUpdate = true; movedItemIDs.Add(lItem.ID); generateFloorMap(); } eventNotification.appendWired(lRoller.ID); if (pUnit != null) // Room unit lifting with roller { float nextZ = pUnit.Z; if (!nextTileIsRoller) { nextZ -= lRoller.Definition.topHeight; } pUnit.X = nextX; pUnit.Y = nextY; pUnit.Z = nextZ; pUnit.requiresUpdate = true; if (!nextTileIsRoller || nextTileUnitInteractiveStance) { this.setRoomUnitTileState(pUnit); } this.gridUnit[lRoller.X, lRoller.Y] = false; this.gridUnit[pUnit.X, pUnit.Y] = true; eventNotification.appendWired(2); eventNotification.appendWired(pUnit.ID); eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(pUnit.Z)); eventNotification.appendClosedValue(stringFunctions.formatFloatForClient(nextZ)); movedRoomUnitIDs.Add(pUnit.ID); } #endregion Updates.Append(eventNotification.ToString()); } if (Updates.Length > 0) { this.sendMessage(Updates.ToString()); } this.mRollerTimer = DateTime.Now.TimeOfDay.TotalSeconds + rollerDelaySeconds; this.mRollerDay = DateTime.Today.DayOfYear; } catch (Exception ex) { Core.Logging.Log("Rollers in room instance of room " + this.roomID + " crashed, exception: " + ex.Message); this.hasRollers = false; } }