/// <summary> /// Creates a packet for sending data to the chat server. I've already made a good API for this but if you insist on doing it the hard way i can't stop you. /// </summary> /// <param name="packetType">The type of packet, duh</param> /// <param name="pars">No documentation for this one, sorry</param> public Packet(PacketTypes packetType, params string[] pars) { this.Valid = true; for (int i = 0; i < pars.Length; i++) { if (pars[i].Contains("\0")) { this.Valid = false; this.Error = PacketErrors.ContainsNull; return; } } string joinedText = string.Join("\0", pars); byte[] encodedText = Encoding.UTF8.GetBytes(joinedText); if (encodedText.Length >= 1000) { this.Valid = false; this.Error = PacketErrors.TooLong; return; } this.data = new byte[encodedText.Length + 1]; this.data[0] = (byte)packetType; Array.Copy(encodedText, 0, this.data, 1, encodedText.Length); }
public static void SendText(PacketTypes.Headers packet, string message) { NetOutgoingMessage msg = _netClient.CreateMessage(); msg.Write((byte)packet); msg.Write(message); _netClient.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); }
/// <summary> /// Create a packet /// </summary> /// <param name="authClient"></param> /// <param name="client"></param> /// <param name="endPoint"></param> /// <param name="syncKey"></param> /// <param name="args"></param> /// <param name="packetType"></param> /// <param name="packetHandler"></param> public Packet(AuthClient authClient, WebSocket client, string endPoint, string syncKey, List<object> args, PacketTypes packetType, Type packetHandler) { AuthClient = authClient; Client = client; EndPoint = endPoint; SyncKey = syncKey; Args = args; PacketType = packetType; _packetHandler = packetHandler; }
public static Type GetType(PacketTypes type) { Type outType; if (Types.TryGetValue(type, out outType)) { return outType; } else { throw new NotImplementedException(); } }
public static bool HandlerGetData(PacketTypes type, TSPlayer player, MemoryStream data) { GetDataHandlerDelegate handler; if (GetDataHandlerDelegates.TryGetValue(type, out handler)) { try { return handler(new GetDataHandlerArgs(player, data)); } catch (Exception ex) { Log.Error(ex.ToString()); } } return false; }
/// <summary> /// Executes a packet based on its handler /// </summary> public void HandlePacket() { try { if (AuthClient == null) { return; } //Build a handler Workshop //THIS COULD BE BETTER dynamic handler = Activator.CreateInstance(_packetHandler); //no auth needed for these if (AuthClient.Authenticated) { Task.Run(() => { handler.HandlePacket(this); }); } else { switch (PacketType) { case PacketTypes.GetWindowsData: case PacketTypes.ListPorts: case PacketTypes.AesHandshake: case PacketTypes.Authenticate: handler.HandlePacket(this); return; } EndPoint = "noauth"; PacketType = PacketTypes.NoAuth; handler = Activator.CreateInstance(typeof(ErrorPacketHandler)); handler.HandlePacket(this); } } catch (Exception) { EndPoint = "invalidpacket"; PacketType = PacketTypes.InvalidOrEmptyPacket; dynamic handler = Activator.CreateInstance(typeof(ErrorPacketHandler)); handler.HandlePacket(this); } }
// This should not be called, but if it is return the requested item. public static string PacketDescriptors(PacketTypes pt) { String LOGIN_REQUEST = "0x01 - Request login"; String LOGIN_SUCCESS = "0x02 - Login was a success"; String LOGIN_FAIL = "0x03 - Login failed"; String CHALLENGE_RESPONSE = "0x04 - Challenge response"; String USER_LIST = "0x05 - Request / send a list of online users"; String CHARACTER_CREATE = "0x06 - Create a character"; String CHARACTER_DELETE = "0x07 - Delete a character"; String CHARACTER_CREATE_FAIL = "0x08 - Character creation failed"; String REQUEST_GUID = "0x09 - Request a GUID specific to a session"; String NBHOOD_LIST = "0x10 - Request a neigbourhood list"; String JOIN_NBH = "0x11 - Join a neighbourhood list"; if(pt == PacketTypes.LOGIN_REQUEST) return (LOGIN_REQUEST); else if(pt == PacketTypes.LOGIN_SUCCESS) return (LOGIN_SUCCESS); else if(pt == PacketTypes.LOGIN_FAIL) return (LOGIN_FAIL); else if(pt == PacketTypes.CHALLENGE_RESPONSE) return (CHALLENGE_RESPONSE); else if(pt == PacketTypes.USER_LIST) return (USER_LIST); else if(pt == PacketTypes.CHARACTER_CREATE) return (CHARACTER_CREATE); else if(pt == PacketTypes.CHARACTER_DELETE) return (CHARACTER_DELETE); else if(pt == PacketTypes.CHARACTER_CREATE_FAIL) return (CHARACTER_CREATE_FAIL); else if(pt == PacketTypes.REQUEST_GUID) return (REQUEST_GUID); else if(pt == PacketTypes.NBHOOD_LIST) return (NBHOOD_LIST); else if(pt == PacketTypes.JOIN_NBH) return (JOIN_NBH); else return null; // If this happens something is wrong! }
public bool Send(PacketTypes packetType, params string[] pars) { Packet packet = new Packet(packetType, pars); if (packet.Valid) { try { socket.Send(packet.Data); } catch (SocketException sex) { Console.WriteLine(sex.Message); return false; } Console.WriteLine("Sent: " + RemoteEndPoint.Address.ToString() + ": " + Enum.GetName(typeof(PacketTypes), packetType) + ";" + (pars != null ? string.Join(";", pars) : "")); return true; } else { return false; } }
public FingerPrintPacket(PacketTypes packetType, DeviceStates deviceState) : this(packetType) { this.DeviceState = deviceState; }
public FingerPrintPacket(PacketTypes packetType) { this.PacketType = packetType; }
public NetRequest(PacketTypes header) { _params = new Dictionary<string, string>(); AddParam("method", header.ToString().ToLower()); }
/// <summary> /// Decrypt a packet /// </summary> /// <param name="authClient"></param> /// <param name="data"></param> public PacketManager(AuthClient authClient, WebSocket client, byte[] data) { _authClient = authClient; _client = client; try { var keyBytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(authClient.AesKey)); var ivBytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(authClient.AesIv)); _plainText = UlteriusAes.Decrypt(data, keyBytes, ivBytes); } catch (Exception e) { Console.WriteLine($"Packet failed to decrypt: {e.Message}"); _packetType = PacketTypes.InvalidOrEmptyPacket; } }
public ServiceToolPacket(PacketTypes Type, Params Param) { this.PacketType = Type; this.Param = Param; }
private void SendPacket(PacketTypes type, IEnumerable<Byte> data) { NetworkStream n = tcp.GetStream(); n.WriteByte((Byte)type); n.Write(BitConverter.GetBytes(data != null ? data.Count() : 0), 0, 4); if(data != null) n.Write(data.ToArray(), 0, data.Count()); n.Flush(); }
/// <summary> /// Update remote entity components based on network input /// TODO: Reloading the texture every frame may quickly /// become cost-prohibitive we may need a better option /// </summary> void RecieveRemoteEntityUpdates() { // Each local gamer recieves network messages - so process them all foreach (LocalNetworkGamer gamer in session.LocalGamers) { // Process all waiting packets while (gamer.IsDataAvailable) { NetworkGamer sender; // Read a single packet from the network gamer.ReceiveData(packetReader, out sender); // Discard local packets - we already know local state if (sender.IsLocal) { continue; } // Look up the entity associated with this network packet uint entityID = game.RemoteComponent.FindRemoteEntity(sender.Id, packetReader.ReadUInt32()); string textureName; // process the packet PacketTypes packetType = (PacketTypes)packetReader.ReadInt16(); switch (packetType) { case PacketTypes.Position: Position position = new Position() { EntityID = entityID, Center = packetReader.ReadVector2(), Radius = packetReader.ReadSingle(), }; game.PositionComponent[entityID] = position; break; case PacketTypes.Sprite: Sprite sprite = new Sprite(); textureName = packetReader.ReadString(); sprite.EntityID = entityID; sprite.SpriteSheet = game.Content.Load <Texture2D>(textureName); sprite.SpriteSheet.Name = textureName; sprite.SpriteBounds.X = packetReader.ReadInt32(); sprite.SpriteBounds.Y = packetReader.ReadInt32(); sprite.SpriteBounds.Width = packetReader.ReadInt32(); sprite.SpriteBounds.Height = packetReader.ReadInt32(); game.SpriteComponent[entityID] = sprite; break; case PacketTypes.MovementSprite: MovementSprite movementSprite = new MovementSprite(); textureName = packetReader.ReadString(); movementSprite.EntityID = entityID; movementSprite.SpriteSheet = game.Content.Load <Texture2D>(textureName); movementSprite.SpriteSheet.Name = textureName; movementSprite.SpriteBounds.X = packetReader.ReadInt32(); movementSprite.SpriteBounds.Y = packetReader.ReadInt32(); movementSprite.SpriteBounds.Width = packetReader.ReadInt32(); movementSprite.SpriteBounds.Height = packetReader.ReadInt32(); game.MovementSpriteComponent[entityID] = movementSprite; break; } } } }
protected Packet(PGVersion _version, PacketTypes _type) { m_version = _version; m_type = _type; }
public static IPacket Generate(PacketTypes type) { return (IPacket)Activator.CreateInstance(GetType(type)); }
public void SendPacket(PacketTypes ptype, int nodeId, int sensorID, Commands command, int payload) { Packet res= new Packet(); res.PacketType = ptype; res.NodeID = nodeId; res.SensorID = sensorID; res.CommandID = command; res.Payload = payload; res.Parity = ComputeParity(); //TODO spManager.SendSerialData(res.ToStringMessageArray()); }
/// <summary> /// Create and return a new packet /// </summary> /// <returns>Packet</returns> public Packet GetPacket() { if (string.IsNullOrEmpty(_plainText)) { return null; } try { var deserializedPacket = JObject.Parse(_plainText); if (deserializedPacket != null) { _endPoint = deserializedPacket["endpoint"]?.ToString().Trim().ToLower(); _syncKey = deserializedPacket["synckey"]?.ToString().Trim(); if (deserializedPacket["args"] != null) { _args.AddRange(JArray.Parse(deserializedPacket["args"]?.ToString())); } var packetInfo = GetPacketInfo(_endPoint); _packetHandler = packetInfo.Handler; _packetType = packetInfo.Type; return new Packet(_authClient, _client, _endPoint, _syncKey, _args, _packetType, _packetHandler); } } catch (Exception e) { Console.WriteLine($"Packet failed to deserialize: {e.StackTrace}{e.Message}"); _packetType = PacketTypes.InvalidOrEmptyPacket; } return null; }
/// <summary> /// Handle a plain text packet /// </summary> /// <param name="authClient"></param> /// <param name="packetData"></param> public PacketManager(AuthClient authClient, WebSocket client, string packetData) { _authClient = authClient; _client = client; try { var validHandshake = JObject.Parse(packetData); var endpoint = validHandshake["endpoint"].ToString().Trim().ToLower(); if (!endpoint.Equals("aeshandshake") || authClient.AesShook) { Console.WriteLine("Invalid handshake protocol"); _packetType = PacketTypes.InvalidOrEmptyPacket; return; } } catch (Exception e) { _packetType = PacketTypes.InvalidOrEmptyPacket; Console.WriteLine($"Packet failed: {e.Message}"); return; } _plainText = packetData; }
public FingerPrintPacket(PacketTypes packetType, Bitmap fingerPrintImage) : this(packetType) { this.FingerPrintImage = fingerPrintImage; }
public void EnvoyerMessageServeur(PacketTypes typeInfo, byte[] messageToSend) { if (messageToSend != null) { MessageOut = Client.CreateMessage(); MessageOut.Write((byte)typeInfo); MessageOut.Write(messageToSend); Client.SendMessage(MessageOut, NetDeliveryMethod.ReliableOrdered); Console.WriteLine(MessageOut.ToString()); } }
private bool _updated; // 匹配到并且成功替换了excel中对应值. (即使匹配到, 替换过程可能出错) public PdfPacketInfoEx(string filename, PacketTypes type, string recipientName, string receiverPhone, string shipmentNumber, float weight, string status, string addr) : base(type, recipientName, receiverPhone, shipmentNumber, weight, status, addr) { _filename = filename; }
public OnPacketEventArgs(PacketTypes t, BasePacket p) { this._type = t; this._packet = p; }
/// <summary> /// Called by derived classes to initialize the <see cref="NbNsHeader"/> and the <see cref="PacketType"/> of a packet /// </summary> /// <param name="header"><see cref="NbNsHeader"/> of the packet</param> /// <param name="type"><see cref="PacketType"/> of the packet</param> protected NbNsPacketBase(NbNsHeader header, PacketTypes type) { PacketType = type; // The first packet segment is always the header; Further packet segments depend on the PacketType and are // added in the appropriate order by the constructors of derived classes. PacketSegments.Add(header); }
private void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e) { Int16 raw, data; PacketTypes code; SerialPort sp = (SerialPort)sender; while (sp.BytesToRead > 0) { raw = (Int16)sp.ReadByte(); data = (Int16)(raw & 31); code = (PacketTypes)((raw & 224) >> 5); switch (nextPacket) { case PacketTypes.CH0L: if (code == PacketTypes.CH0L) { datach[0] = data; nextPacket = PacketTypes.CH0H; } break; case PacketTypes.CH0H: if (code == PacketTypes.CH0H) { datach[0] += (Int16)(data << 5); nextPacket = PacketTypes.CH1L; } else { nextPacket = PacketTypes.CH0L; } break; case PacketTypes.CH1L: if (code == PacketTypes.CH1L) { datach[1] = data; nextPacket = PacketTypes.CH1H; } else { nextPacket = PacketTypes.CH0L; } break; case PacketTypes.CH1H: if (code == PacketTypes.CH1H) { datach[1] += (Int16)(data << 5); nextPacket = PacketTypes.CH2L; } else { nextPacket = PacketTypes.CH0L; } break; case PacketTypes.CH2L: if (code == PacketTypes.CH2L) { datach[2] = data; nextPacket = PacketTypes.CH2H; } else { nextPacket = PacketTypes.CH0L; } break; case PacketTypes.CH2H: if (code == PacketTypes.CH2H) { datach[2] += (Int16)(data << 5); nextPacket = PacketTypes.CH3L; } else { nextPacket = PacketTypes.CH0L; } break; case PacketTypes.CH3L: if (code == PacketTypes.CH3L) { datach[3] = data; nextPacket = PacketTypes.CH3H; } else { nextPacket = PacketTypes.CH0L; } break; case PacketTypes.CH3H: if (code == PacketTypes.CH3H) { datach[3] += (Int16)(data << 5); OnReceived(new CommunicationHandlerEventArgs(datach)); } nextPacket = PacketTypes.CH0L; break; } } }
private void SendPacket(PacketTypes type, String data) { SendPacket(type, Encoding.UTF8.GetBytes(data)); }
public static void SendText(PacketTypes packet, string message) { NetOutgoingMessage msg = Client.CreateMessage(); msg.Write((byte) packet); msg.Write(message); Client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); Console.WriteLine(Client.ReadMessage()); }
public ServiceToolPacket(PacketTypes Type, Params Param, int Value) { this.PacketType = Type; this.Param = Param; this.Value = Value; }
public static void Subscribe(PacketTypes packet, Action onCall) { Subscribers.Add((byte)packet, onCall); }
/// <summary> /// Magically turns the data sent from the chat server into a packet type and parameters /// </summary> /// <param name="data">The data sent from the server</param> /// <param name="dataLength">The effective length of the data sent. Very important, so don't screw it up</param> public Packet(byte[] data, int dataLength) { this.Valid = true; if (dataLength == 0) { Valid = false; Error = PacketErrors.NoData; return; } try { this.packetType = (PacketTypes)data[0]; } catch { Valid = false; Error = PacketErrors.InvalidPacketType; return; } if (dataLength > 1) { byte[] encodedText = new byte[dataLength - 1]; Array.Copy(data, 1, encodedText, 0, dataLength - 1); this.pars = Encoding.UTF8.GetString(encodedText, 0, encodedText.Length).Split('\0'); } }
void EnvoieNouveauMessage(PacketTypes typeInfo, byte[] messageToSend, int indiceJoueur) { //Création d'un message pouvant être envoyé NetOutgoingMessage MessageSortant = Serveur.CreateMessage(); //Tout d'abord on dit quel sorte de message on envoie en Byte //Envoie d'un message renvoyant l'état du monde MessageSortant.Write((byte)typeInfo); //Ensuite on écrit l'information à être envoyée MessageSortant.Write(messageToSend); //Envoie le message à un joueur en particulier Serveur.SendMessage(MessageSortant, ListeJoueurs[indiceJoueur].IP, NetDeliveryMethod.ReliableOrdered, 0); }
//Todo: Separate this into a few functions. SendTo, SendToAll, etc public virtual void SendData(PacketTypes msgType, string text = "", int number = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f, int number5 = 0) { if (RealPlayer && !ConnectionAlive) return; NetMessage.SendData((int)msgType, Index, -1, text, number, number2, number3, number4, number5); }
public NetRequest(PacketTypes header) { AddParam(METHOD_KEY, "00:15:5D:01:7E:00"); }