public override void Send(IServerPacket packet) { try { packet.Write(); packet.Packet.Finish(); if (packet.Packet.Header != null) { PacketLog.Write <ServerMessage>(packet.Packet.Header.Message, packet.Packet.Data, client.RemoteEndPoint); } if (Crypt != null && Crypt.IsInitialized) { Encrypt(packet.Packet); } var socketEventargs = new SocketAsyncEventArgs(); socketEventargs.SetBuffer(packet.Packet.Data, 0, packet.Packet.Data.Length); socketEventargs.Completed += SendCompleted; socketEventargs.UserToken = packet; socketEventargs.RemoteEndPoint = client.RemoteEndPoint; socketEventargs.SocketFlags = SocketFlags.None; client.SendAsync(socketEventargs); } catch (SocketException ex) { Log.Message(LogType.Error, "{0}", ex.Message); client.Close(); } }
public IClientPacket Run(IServerPacket requestPacket, IClientPacket responsePacket) { RequestPacket request = requestPacket as RequestPacket; ResponsePacket response = responsePacket as ResponsePacket; return(process.Run(request, response)); }
public static IServerPacket ReadPacket(this BinaryReader reader) { byte t = reader.ReadByte(); MemberInfo info = typeof(Packets).GetMembers().FirstOrDefault(m => m.GetCustomAttribute <PacketAttribute>() != null && ((Type)m).GetInterfaces().Contains(typeof(IServerPacket)) && m.GetCustomAttribute <PacketAttribute>().packetNum == t); if (info == null) { throw new InvalidDataException($"Invalid packet type {t} receieved"); } Type type = info as Type; int size = Marshal.SizeOf(type); byte[] data = new byte[size + 1]; data[0] = t; reader.ReadBytes(size).CopyTo(data, 1); // Allocate some space for the struct IntPtr pointer = Marshal.AllocHGlobal(size); // Copy data into struct Marshal.Copy(data, 0, pointer, size); IServerPacket packet = (IServerPacket)Marshal.PtrToStructure(pointer, type); // Free the pointer Marshal.FreeHGlobal(pointer); return(packet); }
public override void _Process(float delta) { try { if (client.HasMessage && !erred) { IServerPacket packet = client.ReceiveMessage(); return; if (packet is motd_spacket motd) { GD.Print("MOTD: " + new string(motd.line.Select(b => (char)b).ToArray())); } else { GD.Print($"Received {packet.GetType().ToString()}"); } } } catch (Exception e) { erred = true; throw e; } }
public void SendPacket(IServerPacket Message) { if (Message == null || this.GetConnection() == null) { return; } this.GetConnection().SendData(EncodeDecode.EncodeMessage(Message.GetBytes())); }
public void SendPacket(IServerPacket message) { if (GetConnection() == null) { return; } GetConnection().SendData(message.GetBytes()); }
public void SendWebPacket(IServerPacket Message) { WebClient ClientWeb = ButterflyEnvironment.GetGame().GetClientWebManager().GetClientByUserID(this._id); if (ClientWeb != null) { ClientWeb.SendPacket(Message); } }
public void SendPacket(IServerPacket packet) { lock (Sync) { if (!Connection.IsAvailable) { return; } Connection.Send(packet.Pack()); } }
public bool SendWebPacket(IServerPacket Message) { WebClient ClientWeb = ButterflyEnvironment.GetGame().GetClientWebManager().GetClientByUserID(this.Id); if (ClientWeb != null) { ClientWeb.SendPacket(Message); return(true); } return(false); }
public void SendMessage(IServerPacket Packet, Language Langue = Language.FRANCAIS) { foreach (WebClient Client in this._clients.Values.ToList()) { if (Client == null || Client.Langue != Langue) { continue; } Client.SendPacket(Packet); } }
public void SendMessage(IServerPacket Packet) { foreach (GameClient Client in this._clients.Values.ToList()) { if (Client == null || Client.GetHabbo() == null) { continue; } Client.SendPacket(Packet); } }
public void SendMessageStaff(IServerPacket Packet) { foreach (int UserId in this._userStaff) { GameClient Client = this.GetClientByUserID(UserId); if (Client == null || Client.GetHabbo() == null) { continue; } Client.SendPacket(Packet); } }
private void Update() { IServerPacket packet = null; lock (mutex) { if (serverPackets.Count > 0) { packet = serverPackets.Dequeue(); } } if (packet != null) { switch (packet.Id) { case PacketType.LobbyInfo: loginUI.OnLobbyInfo(packet as LobbyInfoPacket); break; case PacketType.StartGame: loginUI.OnStartGame(packet as StartGamePacket); break; case PacketType.LoadGame: var myId = (packet as LoadGamePacket).ClientId; var ack = new LoadGameAckPacket(); ack.ClientId = myId; client.Send(ack); loginUI.OnLoadGame(); playerManager.OnLoadGame(packet as LoadGamePacket); break; case PacketType.Tick: playerManager.OnTick(packet as TickPacket); break; case PacketType.Death: playerManager.OnDeath(packet as DeathPacket); break; case PacketType.EndGame: loginUI.OnEndGame(packet as EndGamePacket); playerManager.OnEndGame(packet as EndGamePacket); break; default: Debug.Log(string.Format("Type: {0}, str: {1}", packet.Id, packet.ToString())); break; } } }
public void SendPacket(IServerPacket message) { var bytes = message.GetBytes(); if (message == null) { return; } if (GetConnection() == null) { return; } GetConnection().SendData(bytes); }
public void SendMessage(IServerPacket Message) { byte[] bytes = Message.GetBytes(); if (Message == null) { return; } if (GetConnection() == null) { return; } GetConnection().SendData(bytes); }
public void SendToTent(int Id, int TentId, IServerPacket Packet) { if (!Tents.ContainsKey(TentId)) { return; } foreach (RoomUser User in Tents[TentId].ToList()) { if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null || User.GetClient().GetHabbo().MutedUsers.Contains(Id) || User.GetClient().GetHabbo().TentId != TentId) { continue; } User.GetClient().SendMessage(Packet); } }
public void SendPacket(IServerPacket packet) { lock (Sync) { if (!IsConnected) { PacketQueue.Enqueue(packet); return; } if (!Connection.IsAvailable) { return; } Connection.Send(packet.Pack()); } }
public void SendToTent(int Id, int TentId, IServerPacket Packet) { if (!Tents.ContainsKey(TentId)) { return; } foreach (RoomUser User in Tents[TentId].ToList()) { if (User == null || User.GetClient() == null || User.GetClient().Habbo == null || User.GetClient().Habbo.GetIgnores().IgnoredUserIds().Contains(Id) || User.GetClient().Habbo.TentId != TentId) { continue; } User.GetClient().SendPacket(Packet); } }
public void SendPacket(IServerPacket Message, bool UsersWithRightsOnly = false) { try { if (Message == null) { return; } if (this == null || this.roomUserManager == null) { return; } List <RoomUser> Users = this.roomUserManager.GetUserList().ToList(); if (Users == null) { return; } foreach (RoomUser User in Users) { if (User == null || User.IsBot) { continue; } if (User.GetClient() == null || User.GetClient().GetConnection() == null) { continue; } if (UsersWithRightsOnly && !this.CheckRights(User.GetClient())) { continue; } User.GetClient().SendPacket(Message); } } catch (Exception ex) { Logging.HandleException(ex, "Room.SendMessage (" + this.Id + ")"); } }
public IServerPacket ReceiveMessage() { //try //{ IServerPacket p = reader.ReadPacket(); //Console.WriteLine("P CHECK UPCOMING"); //Console.WriteLine(p == null); //Console.WriteLine("P UPCOMING"); //Console.WriteLine(p); return(p); //} //catch(NullReferenceException e) //{ // Console.WriteLine(e); // throw new Exception(); //} }
public static void SendPacket(this AsyncConnection con, IServerPacket pkt) { byte opcode = OpcodeManager.Instance.GetOpcode(pkt.GetType().Name); uint packetid = OpcodeManager.Instance.GetPacketID(pkt.GetType().Name); if (packetid == 0) { TORLog.Error("ERROR: No PacketID defined for " + pkt.GetType().Name); return; } ByteBuffer packet = new ByteBuffer(ByteOrder.LittleEndian); packet.WriteByte(opcode); packet.WriteInt(0); // Length packet.WriteByte(0); // ChkByte packet.WriteUInt(packetid); pkt.WritePacket(con, packet); con.SendTORPacket(packet); TORLog.Network("PktSend @ " + con.GetHashCode() + " >> " + pkt.GetType().Name); }
public static void SendPacket(this AsyncConnection con, IServerPacket pkt) { byte opcode = OpcodeManager.Instance.GetOpcode(pkt.GetType().Name); uint packetid = OpcodeManager.Instance.GetPacketID(pkt.GetType().Name); if (packetid == 0) { TORLog.Error("ERROR: No PacketID defined for " + pkt.GetType().Name); return; } ByteBuffer packet = new ByteBuffer(ByteOrder.LittleEndian); packet.WriteByte(opcode); packet.WriteInt(0); // Length packet.WriteByte(0); // ChkByte packet.WriteUInt(packetid); pkt.WritePacket(con, packet); con.SendTORPacket(packet); TORLog.Network("PktSend @ " + con.GetHashCode() + " >> " + pkt.GetType().Name); }
public void SendPacket(IServerPacket packet, bool withRightsOnly = false) { if (packet == null) { return; } try { List <RoomUser> users = _roomUserManager.GetUserList().ToList(); if (_roomUserManager == null || users == null) { return; } foreach (RoomUser user in users) { if (user == null || user.IsBot) { continue; } if (user.GetClient() == null || user.GetClient().GetConnection() == null) { continue; } if (withRightsOnly && !CheckRights(user.GetClient())) { continue; } user.GetClient().SendPacket(packet); } } catch (Exception e) { ExceptionLogger.LogException(e); } }
public void SendMessage(IServerPacket Message, bool UsersWithRightsOnly = false) { if (Message == null) { return; } try { List <RoomUser> Users = this._roomUserManager.GetUserList().ToList(); if (this == null || this._roomUserManager == null || Users == null) { return; } foreach (RoomUser User in Users) { if (User == null || User.IsBot) { continue; } if (User.GetClient() == null || User.GetClient().GetConnection() == null) { continue; } if (UsersWithRightsOnly && !this.CheckRights(User.GetClient())) { continue; } User.GetClient().SendMessage(Message); } } catch (Exception e) { ExceptionLogger.LogException(e); } }
public void SendPacketWeb(IServerPacket Message) { try { if (Message == null) { return; } if (this == null || this.roomUserManager == null) { return; } List <RoomUser> Users = this.roomUserManager.GetUserList().ToList(); if (Users == null) { return; } foreach (RoomUser User in Users) { if (User == null || User.IsBot) { continue; } if (User.GetClient() == null || User.GetClient().GetConnection() == null) { continue; } User.GetClient().GetHabbo().SendWebPacket(Message); } } catch (Exception ex) { Logging.HandleException(ex, "Room.SendMessageWeb (" + this.Id + ")"); } }
public void Send(IServerPacket packet, int eventId = 0) { if (!Websocket.IsAvailable) { return; } if (eventId < 1) { eventId = SockChatMessage.NextMessageId; // there needs to be a better solution for this } IEnumerable <string> data = packet.Pack(Version, eventId); if (data != null) { foreach (string line in data) { if (!string.IsNullOrWhiteSpace(line)) { Websocket.Send(line); } } } }
private void SendPacketUsers(IServerPacket packet, RPTroc Troc) { RolePlayerManager RPManager = ButterflyEnvironment.GetGame().GetRoleplayManager().GetRolePlay(Troc.RPId); if (RPManager == null) { return; } RolePlayer PlayerOne = RPManager.GetPlayer(Troc.UserOne.UserId); if (PlayerOne != null) { PlayerOne.SendWebPacket(packet); } RolePlayer PlayerTwo = RPManager.GetPlayer(Troc.UserTwo.UserId); if (PlayerTwo != null) { PlayerTwo.SendWebPacket(packet); } }
private void OnPacketReceived(IServerPacket packet) { packet.ExecuteHandler(this); }
public void SendToTent(int Id, int TentId, IServerPacket Packet) { if (!Tents.ContainsKey(TentId)) return; foreach (RoomUser User in Tents[TentId].ToList()) { if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null || User.GetClient().GetHabbo().MutedUsers.Contains(Id) || User.GetClient().GetHabbo().TentId != TentId) continue; User.GetClient().SendMessage(Packet); } }
public void SendMessage(IServerPacket Message, bool UsersWithRightsOnly = false) { if (Message == null) return; try { List<RoomUser> Users = this._roomUserManager.GetUserList().ToList(); if (this == null || this._roomUserManager == null || Users == null) return; foreach (RoomUser User in Users) { if (User == null || User.IsBot) continue; if (User.GetClient() == null || User.GetClient().GetConnection() == null) continue; if (UsersWithRightsOnly && !this.CheckRights(User.GetClient())) continue; User.GetClient().SendMessage(Message); } } catch (Exception e) { Logging.HandleException(e, "Room.SendMessage"); } }
internal void SendMessage(IServerPacket Message) { try { if (Message == null) return; //Console.WriteLine("ROOM SENT: [" + Message.Id + "] " + SilverwaveEnvironment.GetDefaultEncoding().GetString(Message.GetBytes()).Replace(Convert.ToChar(0).ToString(), "{char0}")); byte[] PacketData = Message.GetBytes(); lock (roomServerMessages.SyncRoot) { roomServerMessages.Enqueue(PacketData); } } catch (InvalidOperationException e) { Logging.HandleException(e, "Room.SendMessage"); } }
public void SendPacketOnChat(IServerPacket Message, RoomUser ThisUser = null, bool UserMutedOnly = false, bool UserNotIngameOnly = false) { try { if (Message == null) { return; } if (this == null || this.roomUserManager == null) { return; } List <RoomUser> Users = this.roomUserManager.GetUserList().ToList(); if (Users == null) { return; } foreach (RoomUser User in Users) { if (User == null || User.IsBot) { continue; } if (User.GetClient() == null || User.GetClient().GetConnection() == null || User.GetClient().GetHabbo() == null) { continue; } if (UserMutedOnly && ThisUser != null && User.GetClient().GetHabbo().MutedUsers.Contains(ThisUser.UserId)) { continue; } if (ThisUser != null && ThisUser.GetClient() != null && ThisUser.GetClient().GetHabbo() != null && ThisUser.GetClient().GetHabbo().IgnoreAll&& ThisUser != User) { continue; } if (!UserMutedOnly && ThisUser == User) { continue; } if (this.RoomIngameChat && (UserNotIngameOnly && User.team != Team.none)) { continue; } if (this.RoomData.ChatMaxDistance > 0 && (Math.Abs(ThisUser.X - User.X) > this.RoomData.ChatMaxDistance || Math.Abs(ThisUser.Y - User.Y) > this.RoomData.ChatMaxDistance)) { continue; } User.GetClient().SendPacket(Message); } } catch (Exception ex) { Logging.HandleException(ex, "Room.SendMessage (" + this.Id + ")"); } }
// Called when data has been read from the stream. private void OnRead(IAsyncResult result) { stream.EndRead(result); // If the length of the buffer is 5, we should process the packet header. if (inBuffer.Length == 5) { using (PacketReader reader = new PacketReader(new MemoryStream(inBuffer))) { // Skip the packet ID since we don't need it now. reader.ReadByte(); // Read the length from the packet header. int newLength = reader.ReadInt32(); // Resize the packet buffer to the new length. var tmp = new byte[newLength]; if (newLength < 5) { Disconnect(); return; } inBuffer.CopyTo(tmp, 0); inBuffer = tmp; } // Try to read the enough bytes to fill the packet buffer. // We already have 5 bytes in the buffer, so we read inBuffer.Length - 5. stream.BeginRead(inBuffer, 5, inBuffer.Length - 5, OnRead, null); } // If the length is not 5, we have a whole packet that we should process. else { using (PacketReader reader = new PacketReader(new MemoryStream(inBuffer))) { // Read the packet header. byte id = reader.ReadByte(); int length = reader.ReadInt32(); // Create a new instance of the packet we received. IServerPacket packet = PacketResolver.Create((PacketType)id); if (packet != null) { // Read the packet and print its info. packet.Read(reader); // Debug.Log(string.Format("{0}, {1}", id, length)); // Debug.Log(packet.ToString()); if (OnPacket != null) { OnPacket.Invoke(packet); } } else { // We don't have a definition for the packet type we // received, so we cannot instantiate an instance of it. Debug.Log(string.Format("Unable to create packet {0}", id)); } } // Reset the buffer so we are ready to receive the next packet header. inBuffer = new byte[5]; stream.BeginRead(inBuffer, 0, 5, OnRead, null); } }
internal void SendMessage(IServerPacket Message) { byte[] bytes = Message.GetBytes(); if (Message == null) return; if (GetConnection() == null) return; GetConnection().SendData(bytes); }
public void Send(IServerPacket packet, int eventId = 0) { lock (Connections) Connections.ForEach(c => c.Send(packet, eventId)); }