public void ForwardPacket(IOutPacket packet) { using (var stream = new MemoryStream(InitialPacketCapacity)) { // write a placeholder for the size of the packet. will set it properly in a moment stream.Write(twoZeroBytes, 0, twoZeroBytes.Length); // write the actual packet data (including the opcode) packet.Write(stream); // now write the real size (in big endian), excluding the size of the size stream.Position = 0; stream.Write(Arrays.Reverse(BitConverter.GetBytes(checked ((ushort)(stream.Length - twoZeroBytes.Length)))), 0, sizeof(ushort)); // encrypt the header of the packet var array = stream.ToArray(); if (array.Length < ShardPacketCipher.SendLength) { throw new ArgumentException($"packet is too short. must be at least {ShardPacketCipher.SendLength - twoZeroBytes.Length} bytes", nameof(packet)); } packetCipher.EncryptHeader(new ArraySegment <byte>(array, 0, ShardPacketCipher.SendLength)); Session.Send(array); } }
public void ForwardPacket(IOutPacket packet) { using (var stream = new MemoryStream()) { packet.Write(stream); Session.Send(stream.ToArray()); } }
public Task Send(IOutPacket message) { if (IsOnline().Result) { var session = GrainFactory.GetGrain <IShardSession>(GetSessionId().Result); session.Send(message); } else { GetLogger().Warn($"tried to send packet of type {message.GetType().Name} to not-online {nameof(Character)} {State.Name}"); } return(Task.CompletedTask); }
/// <summary> /// Sends a packet to the game server. /// </summary> /// <param name="packet">The packet.</param> public void SendPacket(IOutPacket packet) { SendPacket((GameServerOutPacketType)packet.Id, packet.GetBytes()); }
public Task Send(IOutPacket packet) { sessionObservers.Notify(receiver => receiver.ForwardPacket(packet)); return(Task.CompletedTask); }
/// <summary> /// Sends a packet to the chat server. /// </summary> /// <param name="packet">The packet.</param> public void SendPacket(IOutPacket packet) { SendPacket((ChatServerPacketType)packet.Id, packet.GetBytes()); }
public Task SendPacketAsync(IOutPacket packet) { return(_channel.WriteAndFlushAsync(packet)); }
/// <summary> /// Creates a new Authentication Request Packet /// </summary> /// <param name="authenticator">The SaveData that needs to be compared to the online version for authentication</param> public OutgoingPacket(SaveData authenticator) { Type = OutgoingPacketType.AUTH; PacketContainer = new OAuthenticatePacket(authenticator); }
/// <summary> /// Creates a new Outgoing Trade Packet with the SET_POKEMON Trade Command /// </summary> /// <param name="pokemonToTrade">The SeriPokemon that needs to be set (visible to the other player)</param> public OutgoingPacket(TradeCommand command, SeriPokemon pokemonToTrade) { Type = OutgoingPacketType.TRADE; PacketContainer = new OTradePacket(command, pokemonToTrade); }
/// <summary> /// Creates a new empty Outgoing Trade Packet with the set TradeCommand /// </summary> /// <param name="tradeCommand"></param> public OutgoingPacket(TradeCommand tradeCommand) { Type = OutgoingPacketType.TRADE; PacketContainer = new OTradePacket(tradeCommand, ""); }