public void Process(Entities.User u, Core.Networking.InPacket packet) { string[] blocks = packet.Blocks; ushort subId = 0; try { ushort.TryParse(blocks[3], out subId); }catch { subId = 0; } if (subId > 0 && Enum.IsDefined(typeof(Enums.GameSubs), subId)) { this.type = (Enums.GameSubs)subId; lock (handleLock) { this.packet = packet; mapData = false; updateLobby = false; selfTarget = false; respond = false; this.blocks = new string[blocks.Length - 4]; Array.Copy(blocks, 4, this.blocks, 0, this.blocks.Length); this.Room = u.Room; Entities.Player p = null; selfTarget = false; try { this.Room.Players.TryGetValue(u.RoomSlot, out p); } catch { p = null; } if (p != null) { this.Player = p; roomSlot = p.Id; try { Handle(); } catch { respond = false; } if (respond) { string[] packetData; if (errorCode == 1) { packetData = new string[this.blocks.Length + 5]; packetData[0] = errorCode.ToString(); packetData[1] = roomSlot.ToString(); packetData[2] = Room.ID.ToString(); packetData[3] = blocks[2]; // 2 - 0 packetData[4] = ((ushort)type).ToString(); // Type Array.Copy(this.blocks, 0, packetData, 5, this.blocks.Length); } else { packetData = new string[] { errorCode.ToString() }; } // Generate packet buffer // byte[] buffer = new Packets.GameData(packetData).BuildEncrypted(); if (errorCode > 1 || selfTarget) { u.Send(buffer); } else { Room.Send(buffer); } if (mapData) { u.Send(new Packets.MapData(Room)); } if (updateLobby) // Send a update to the lobby :) { byte roomPage = (byte)Math.Floor((decimal)(Room.ID / 8)); var targetList = Managers.ChannelManager.Instance.Get(Room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null); if (targetList.Count() > 0) { byte[] outBuffer = new Packets.RoomUpdate(Room, true).BuildEncrypted(); foreach (Entities.User usr in targetList) { usr.Send(outBuffer); } } } } } } } else { u.Disconnect(); // Wrong id? } }
public void SaytoRoom(string _message, Entities.Room Room) { string _codedMessage = MessageTranslator(_message); Room.Send(GetPacket(ChatType.Room_ToAll, _codedMessage)); }