public static void HandleMessenger(Character chr, Packet packet) { byte mode = packet.ReadByte(); switch (mode) { case 0: Server.Instance.CenterConnection.MessengerJoin(packet.ReadInt(), chr); break; case 2: Server.Instance.CenterConnection.MessengerLeave(chr.ID); break; case 3: { var invited = packet.ReadString(); log.Info($"{chr.Name} invites {invited}"); Server.Instance.CenterConnection.MessengerInvite(chr.ID, invited); break; } case 5: Server.Instance.CenterConnection.MessengerBlock(chr.ID, packet.ReadString(), packet.ReadString(), packet.ReadByte()); break; case 6: { string message = packet.ReadString(); if (MessagePacket.ShowMuteMessage(chr)) { log.Info($"[MUTED] {chr.Name}: {message}"); } else { log.Info($"{chr.Name}: {message}"); Server.Instance.CenterConnection.MessengerChat(chr.ID, message); } break; } case 7: Server.Instance.CenterConnection.MessengerAvatar(chr); break; default: Program.MainForm.LogAppend("UNKNOWN MESSENGER OP: " + mode); break; } }
public static void HandlePacket(Character pCharacter, Packet pPacket) { //MessagePacket.SendNotice("PACKET: " + pPacket.ToString(), pCharacter); byte Type = pPacket.ReadByte(); switch (Type) { case 0: // Create miniroom { if (pCharacter.AssertForHack(!pCharacter.CanAttachAdditionalProcess, "Trying to create a miniroom while he cannot attach additional process.")) { return; } CreateMiniRoomBase(pCharacter, pPacket); break; } case 2: // Invite To miniroom { if (pCharacter.Room == null) { InviteResult(pCharacter, 1); return; // NOT OPENED OR FULL } int playerid = pPacket.ReadInt(); Character victim = pCharacter.Field.GetPlayer(playerid); if (victim == null) { miniroomLog.Info($"{pCharacter.Name} fails to invite charid {playerid}: not found?"); // Not found! InviteResult(pCharacter, 1); } else if (pCharacter.Room.IsFull()) { miniroomLog.Info($"{pCharacter.Name} fails to invite charid {playerid}: room already full?"); InviteResult(pCharacter, 2, victim.Name); // DEM REAL DEAL } else if ((pCharacter.IsGM == false && victim.IsGM) || (pCharacter.IsGM && victim.IsGM == false)) { miniroomLog.Info($"{pCharacter.Name} fails to invite charid {playerid}: non-admin tried to invite admin or vice versa"); InviteResult(pCharacter, 1); } else { miniroomLog.Info($"{pCharacter.Name} invited {victim.Name} (charid {playerid})"); Invite(pCharacter.Room, pCharacter, victim); } break; } case 3: // Decline Invite { int roomid = pPacket.ReadInt(); miniroomLog.Info($"{pCharacter.Name} declined invite."); if (!MiniRoomBase.MiniRooms.ContainsKey(roomid)) { // REPORT //ReportManager.FileNewReport("Tried opening a trade room without a proper ID.", pCharacter.ID, 0); //MessagePacket.SendNotice("Tried opening a trade room without a proper ID. ID was: " + roomid.ToString(), pCharacter); return; } MiniRoomBase mrb = MiniRoomBase.MiniRooms[roomid]; //if (mrb.IsFull()) //{ //} break; } case 4: // Enter Room { EnterMiniRoom(pCharacter, pPacket); break; } case 0x06: // Chat { if (pCharacter.Room == null) { return; } var text = pPacket.ReadString(); var chatLogLine = pCharacter.Name + ": " + text; if (MessagePacket.ShowMuteMessage(pCharacter)) { miniroomChatLog.Info("[MUTED] " + chatLogLine); } else { miniroomChatLog.Info(chatLogLine); Chat(pCharacter.Room, pCharacter, text, -1); } break; } case 0x12: //Add item to Player Shop { if (pCharacter.Room == null) { return; } byte inventory = pPacket.ReadByte(); short inventoryslot = pPacket.ReadShort(); short bundleamount = pPacket.ReadShort(); short AmountPerBundle = pPacket.ReadShort(); int price = pPacket.ReadInt(); PlayerShop.HandleShopUpdateItem(pCharacter, inventory, inventoryslot, bundleamount, AmountPerBundle, price); break; } case 0x13: //Buy item from shop { if (pCharacter.Room == null) { return; } byte slot = pPacket.ReadByte(); short bundleamount = pPacket.ReadShort(); PlayerShop ps = MiniRoomBase.PlayerShops[pCharacter.Room.ID]; if (ps != null) { ps.BuyItem(pCharacter, slot, bundleamount); } break; } case 0xA: //Leave { MiniRoomBase mr = pCharacter.Room; if (mr == null) { return; } miniroomLog.Info($"{pCharacter.Name} declined invite."); if (mr.Type == MiniRoomBase.RoomType.Trade) { for (int i = 0; i < 2; i++) { Character chr = mr.Users[i]; Character leader = mr.Users[0]; if (chr == null) { continue; } mr.RemovePlayer(chr, 1); //mr.Users[i] = null; //send this after all characters are removed } } else if (mr.Type == MiniRoomBase.RoomType.PersonalShop) { mr.RemovePlayerFromShop(pCharacter); } else if (mr.Type == MiniRoomBase.RoomType.Omok) { //MessagePacket.SendNotice("leave omok", pCharacter); Omok omok = MiniRoomBase.Omoks[pCharacter.Room.ID]; if (pCharacter == omok.Users[0]) { omok.CloseOmok(pCharacter); } else { ShowLeaveRoom(pCharacter.Room, pCharacter, 2); omok.RemovePlayer(pCharacter, 1); } } break; } case 0xB: //Add announce box { if (pCharacter.Room == null) { return; } MiniGamePacket.AddAnnounceBox(pCharacter, (byte)pCharacter.Room.Type, pCharacter.Room.ID, pCharacter.Room.Title, pCharacter.Room.Private, 0, false); byte RoomType = (byte)pCharacter.Room.Type; switch (RoomType) { case 1: { pCharacter.Field.Omoks.Add(pCharacter.Room.ID, MiniRoomBase.Omoks[pCharacter.Room.ID]); break; } case 4: { pCharacter.Field.PlayerShops.Add(pCharacter.Room.ID, MiniRoomBase.PlayerShops[pCharacter.Room.ID]); break; } } break; } case 0x17: //Move Item from player shop to inventory { return; if (pCharacter.AssertForHack(!(pCharacter.Room is PlayerShop), "PlayerShop hack: taking back item while not in playershop")) { return; } byte slot = pPacket.ReadByte(); //reads as byte, sends as short... wtf lol PlayerShop ps = pCharacter.Room as PlayerShop; if (pCharacter.AssertForHack(ps.Owner != pCharacter, "PlayerShop hack: taking back item while not owner")) { return; } ps.HandleMoveItemBack(pCharacter, slot); ps.Items.Remove(slot); break; } case 0x19: //Request tie result { bool result = pPacket.ReadBool(); break; } case 0x20: //Ready { MiniGamePacket.Ready(pCharacter, pCharacter.Room); break; } case 0x21: { MiniGamePacket.UnReady(pCharacter, pCharacter.Room); break; } case 0x22: //Expell user { //Todo : expell break; } case 0x23: { Omok omok = MiniRoomBase.Omoks[pCharacter.Room.ID]; if (omok != null) { MiniGamePacket.Start(pCharacter, pCharacter.Room); omok.GameStarted = true; } break; } case 0x25: { Omok omok = MiniRoomBase.Omoks[pCharacter.Room.ID]; omok.UpdateGame(pCharacter); omok.GameStarted = false; break; } case 0x26: //Place omok piece { Omok omok = MiniRoomBase.Omoks[pCharacter.Room.ID]; if (omok != null) { int X = pPacket.ReadInt(); int Y = pPacket.ReadInt(); byte Piece = pPacket.ReadByte(); if (omok.Stones[X, Y] != Piece && omok.Stones[X, Y] != omok.GetOtherPiece(Piece)) { MiniGamePacket.MoveOmokPiece(pCharacter, pCharacter.Room, X, Y, Piece); omok.AddStone(X, Y, Piece, pCharacter); } else { MiniGamePacket.OmokMessage(pCharacter, pCharacter.Room, 0); } //MessagePacket.SendNotice("X : " + X + " Y : " + Y, pCharacter); if (omok.CheckStone(Piece)) { //MessagePacket.SendNotice("Win!", pCharacter); omok.UpdateGame(pCharacter); Piece = 0xFF; omok.GameStarted = false; } } break; } case 0x1C: { for (int i = 0; i < 2; i++) { if (pCharacter.Room.Users[i] != pCharacter) { MiniGamePacket.RequestHandicap(pCharacter.Room.Users[i], pCharacter.Room); } } break; } case 0x1D: //Request handicap result { bool result = pPacket.ReadBool(); Omok omok = MiniRoomBase.Omoks[pCharacter.Room.ID]; if (omok != null) { if (result == true) { for (int i = 0; i < 2; i++) { if (pCharacter.Room.Users[i] != pCharacter) { if (omok.PlacedStone[i] == false) { MiniGamePacket.RequestHandicapResult(pCharacter, pCharacter.Room, result, 2); omok.TotalStones -= 2; //MessagePacket.SendNotice("removed", pCharacter); } else { MiniGamePacket.RequestHandicapResult(pCharacter, pCharacter.Room, result, 1); omok.TotalStones--; //omok.Stones[omok.LastPlacedStone[(byte)(pCharacter.RoomSlotId + 1)].mX, omok.LastPlacedStone[(byte)(pCharacter.RoomSlotId + 1)].mY] = 0xFF; //MessagePacket.SendNotice("Removed stone", pCharacter); } } } } } break; } default: { if (pCharacter.Room != null) { pCharacter.Room.OnPacket(pCharacter, Type, pPacket); } //MessagePacket.SendNotice("This feature is currently disabled due to maintenance.", pCharacter); break; } } }