コード例 #1
0
        public static CharacterListActionResponsePacket Read(NetPacketReader message)
        {
            var p = new CharacterListActionResponsePacket();

            p.Action = (CharacterListAction)message.GetByte();
            p.Status = (CharacterListStatus)message.GetByte();
            return(p);
        }
コード例 #2
0
        public void Decode(NetPacketReader im)
        {
            NoOfTiles = new Dictionary <Faction, int>();
            Winner    = (Faction)im.GetByte();
            int noFactions = im.GetInt();

            for (int i = 0; i < noFactions; i++)
            {
                NoOfTiles.Add((Faction)im.GetByte(), im.GetInt());
            }
        }
コード例 #3
0
    public static LNSJoinRoomFilter FromReader(NetPacketReader reader)
    {
        int filterCount = reader.GetByte();

        if (filterCount > 0)
        {
            LNSJoinRoomFilter o = new LNSJoinRoomFilter();
            for (int i = 0; i < filterCount; i++)
            {
                o.Set(reader.GetByte(), reader.GetByte());
            }
            return(o);
        }
        return(null);
    }
コード例 #4
0
ファイル: Program.cs プロジェクト: typicalname0/dreamscape
 private void NetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     try
     {
         Player plr = null;
         foreach (Player i in characterFactory.Children)
         {
             if (i.peer == peer)
             {
                 plr = i;
             }
         }
         Console.WriteLine("Data recv.");
         switch ((ClientSend)reader.GetByte())
         {
         case ClientSend.Act:
             LuaFunction actfunc = lua["act"] as LuaFunction;
             actfunc.Call(reader.GetString(), peer, plr);
             break;
         }
     }catch (Exception e)
     {
         NetDataWriter writer = new NetDataWriter();
         writer.Put((byte)NetTypes.Text);
         writer.Put((byte)ModifyTypes.AddSet);
         writer.Put("\nAn internal server error occoured.\n" + e + "\n");
         Console.WriteLine(e);
     }
 }
コード例 #5
0
        public virtual void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            try
            {
                var packetType = reader.GetByte();
                var pt         = (PacketType)packetType;

                switch (pt)
                {
                case PacketType.GameState:
                    break;

                case PacketType.Serialized:
                    NetPacketProcessor.ReadAllPackets(reader, peer);
                    break;

                case PacketType.Command:
                    break;

                case PacketType.SerializedComponent:
                    _onReceivedSerializedComponent.OnNext(new ComponentData {
                        Peer = peer, Reader = reader, DeliveryMethod = deliveryMethod
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e);
            }
        }
コード例 #6
0
        /// <summary>
        /// 处理数据
        /// </summary>
        public void OnRecvData(NetPeer peer, NetPacketReader reader)
        {
            var protoType = (ProtoType)reader.GetByte();
            var protoName = reader.GetString();

            logger.Info("OnRecvData[commandid]:" + protoType + " protoName:" + protoName);

            if (!mHandlers.ContainsKey(protoName))
            {
                protoName = Protocal.Default;
            }
            byte[] bytes = null;
            var    count = reader.GetInt();

            reader.GetBytes(bytes, count);

            IHandler handler = null;

            if (mHandlers.TryGetValue(protoName, out handler))
            {
                try
                {
                    if (handler != null)
                    {
                        handler.OnMessage(peer, bytes);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }
        }
コード例 #7
0
 public void Decode(NetPacketReader im)
 {
     faction    = (Faction)im.GetByte();
     FieldX     = im.GetInt();
     FieldY     = im.GetInt();
     Population = im.GetInt();
 }
コード例 #8
0
ファイル: Peer.cs プロジェクト: tuita520/Davinet
        private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            PacketType packetType = (PacketType)reader.GetByte();

            if (packetType == PacketType.State)
            {
                queuedStatePackets.Enqueue(new StatePacket()
                {
                    PacketReader = reader, PeerID = peer.Id + 1
                });
            }
            // TODO: This is also server only logic.
            else if (packetType == PacketType.Join)
            {
                jitterBuffersByPeerId[peer.Id + 1] = new JitterBuffer(settings.JitterBufferDelayFrames);

                int remoteID = reader.GetInt();
                OnReceivePeerId?.Invoke(remoteID);

                int frame = reader.GetInt();

                StatefulWorld.Instance.Frame = frame;
                remote = new Remote(StatefulWorld.Instance, false, role == Role.ListenClient, remoteID);

                Debug.Log($"Local client assigned id <b>{remoteID}</b>", LogType.Connection);
            }
        }
コード例 #9
0
        public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, SendType sendType)
        {
            var packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }

            var pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.ServerState:
                _cachedServerState.Deserialize(reader);
                OnServerState();     // <- 매번 서버에서 불러주고있음
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader);
                break;

            default:
                Debug.Log($"[Client] OnNetworkReceive - Unhandled packet : {pt}");
                break;
            }
        }
コード例 #10
0
        void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            byte packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }
            PacketType pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.Movement:
                OnInputReceived(reader, peer);
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader, peer);
                break;

            default:
                Debug.Log("Unhandled packet: " + pt);
                break;
            }
        }
コード例 #11
0
ファイル: LocalPeer.cs プロジェクト: kiadorn/SensingSounds
        /// <summary>
        /// Event that runs when a packet is revieved from a peer.
        /// </summary>
        /// <param name="peer">The peer that send a packet.</param>
        /// <param name="reader">The reader to get the packet from.</param>
        /// <param name="deliveryMethod">The type of delivery.</param>
        public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            byte       packetTypeByte = reader.GetByte();
            PacketType packetType     = (PacketType)packetTypeByte;

            switch (packetType)
            {
            case PacketType.Transform:
                otherPlayers[peer].transformPacket.Deserialize(reader);
                break;

            case PacketType.Sounds:
                otherPlayers[peer].PlaySound(reader.GetInt());
                break;

            case PacketType.Stop:
                otherPlayers[peer].StopSound();
                break;

            default:
                Debug.LogError("Unhandled packet: " + packetType);
                break;
            }
            reader.Clear();
        }
コード例 #12
0
ファイル: Packets.cs プロジェクト: Regenhardt/Librelancer
 public static AuthenticationPacket Read(NetPacketReader message)
 {
     return(new AuthenticationPacket()
     {
         Type = (AuthenticationKind)message.GetByte()
     });
 }
コード例 #13
0
ファイル: ClientLogic.cs プロジェクト: d-huch/NetGameExample
        void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            byte packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }
            PacketType pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.Spawn:
                break;

            case PacketType.ServerState:
                _cachedServerState.Deserialize(reader);
                OnServerState();
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader);
                break;

            case PacketType.Shoot:
                _cachedShootData.Deserialize(reader);
                OnShoot();
                break;

            default:
                Debug.Log("Unhandled packet: " + pt);
                break;
            }
        }
コード例 #14
0
        private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            PacketType packetType = (PacketType)reader.GetByte();

            if (packetType == PacketType.State)
            {
                if (remote == null)
                {
                    queuedStatePackets.Enqueue(reader);
                }
                else
                {
                    ReadState(reader);
                }
            }
            // TODO: This is also server only logic.
            else if (packetType == PacketType.Join)
            {
                int remoteID = reader.GetInt();
                int frame    = reader.GetInt();

                StatefulWorld.Instance.Frame = frame;
                remote = new Remote(StatefulWorld.Instance, false, role == Role.ListenClient, remoteID);

                UnityEngine.Debug.Log($"Client assigned id {remoteID}");
            }
        }
コード例 #15
0
        public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, SendType sendType)
        {
            var packetType = reader.GetByte();

            if (packetType >= NetworkGeneral.PacketTypesCount)
            {
                return;
            }
            var pt = (PacketType)packetType;

            switch (pt)
            {
            case PacketType.Movement:
                OnMovement(reader, peer);
                break;

            case PacketType.Serialized:
                _packetProcessor.ReadAllPackets(reader, peer);
                break;

            default:
                Debug.Log($"[Server] OnNetworkReceive - Unhandled packet : {pt}");
                break;
            }
        }
コード例 #16
0
 void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     if (reader.UserDataSize >= 1)
     {
         byte dataType = reader.GetByte();
         OnNetworkEventReceived?.Invoke(dataType, reader);
     }
 }
コード例 #17
0
 public static object Read(NetPacketReader message)
 {
     return(new DestroyPartPacket()
     {
         IDType = message.GetByte(),
         ID = message.GetInt(),
         PartName = message.GetString()
     });
 }
コード例 #18
0
        /// <summary>
        /// Receives data from the network and handles it appropriately.
        /// </summary>
        /// <param name="peer">Peer.</param>
        /// <param name="reader">Reader.</param>
        /// <param name="deliveryMethod">Delivery method.</param>
        void NetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            if (deliveryMethod != Method)
            {
                Logger("Wrong delivery method from peer " + peer.EndPoint.ToString() + ".");
            }

            int Reference = reader.GetByte() + reader.GetByte() * 256 + reader.GetByte() * 65536 + reader.GetByte() * 16777216;

            remote = peer;

            /* Is a reply? */
            bool       IsPWaited;
            PeerWaiter Wtr = null;

            lock (Waiter)
                if (Waiter.ContainsKey(Reference))
                {
                    IsPWaited = true;
                    Wtr       = Waiter[Reference];
                }
                else
                {
                    IsPWaited = false;
                }

            /* Pass back reply */
            if (IsPWaited)
            {
                Wtr.Data = reader.GetRemainingBytes();
                Wtr.Barrier.Set();
                return;
            }

            /* Handle request */
            byte[] Resp = DataCallbacks[Reference](reader.RawData, reader.UserDataOffset + 4, reader.UserDataSize - 4, out int Of, out int Oc);
            byte[] DtS  = new byte[Resp.Length + 4];
            DtS[0] = (byte)(Reference % 256);
            DtS[1] = (byte)(Reference / 256 % 256);
            DtS[2] = (byte)(Reference / 65536 % 256);
            DtS[3] = (byte)(Reference / 16777216 % 256);
            Buffer.BlockCopy(Resp, Of, DtS, 4, Oc);
            peer.Send(DtS, Method);
        }
コード例 #19
0
 public void OnNetworkReceive(NetPeer peer, NetPacketReader data, DeliveryMethod deliveryMethod)
 {
     try
     {
         switch (data.GetByte())
         {
         }
     }
     catch (Exception e) { }
 }
コード例 #20
0
        private static void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            PacketID id = (PacketID)reader.GetByte();

            switch (id)
            {
            case PacketID.PlayerUpdatePacket:

                break;
            }
        }
コード例 #21
0
        public virtual void Reset(NetPacketReader message = null)
        {
            if (message == null)
            {
                if (NetData.PacketConverters.TryGetValue(GetType(), out byte val))
                {
                    PacketType = val;
                }
                return;
            }

            PacketType = message.GetByte();
        }
コード例 #22
0
ファイル: Networker.cs プロジェクト: beef331/rpg
    private static void DoEvent(NetPacketReader reader)
    {
        NetworkEvents evt = (NetworkEvents)reader.GetByte();

        if (!idToEvent.ContainsKey(evt))
        {
            return;
        }
        INetworkEvent netEvent = (INetworkEvent)Activator.CreateInstance(idToEvent[evt]);

        netEvent.ReadPacket(reader);
        netEvent.Invoke();
    }
コード例 #23
0
    public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
    {
        byte messageType = reader.GetByte();

        if (messageType == MESSAGE_OBJECT_BATCH)
        {
            NetworkedObject.NetworkReadAll(reader, peer.Id);
        }
        else if (messageType == MESSAGE_COMPONENT_CUSTOM)
        {
            NetworkedObject.HandleComponentMessage(reader, peer.Id);
        }
    }
コード例 #24
0
        public void Decode(NetPacketReader im)
        {
            this.LoginMsgType = im.GetByte();
            this.PlayerName   = im.GetString();
            switch ((LoginMsg)LoginMsgType)
            {
            case LoginMsg.INIT:
                break;

            case LoginMsg.FACTIONLOAD:
                int f_lenght = im.GetInt();
                availableFactions = new Faction[f_lenght];
                for (int i = 0; i < availableFactions.Length; i++)
                {
                    availableFactions[i] = (Faction)im.GetByte();
                }
                break;

            case LoginMsg.FACTIONSELECT:
                this.Faction = im.GetByte();
                break;
            }
        }
コード例 #25
0
ファイル: MessageListener.cs プロジェクト: jacoblontoc/H3MP
        public void OnNetworkReceive(NetPeer rawPeer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            var peer = _peers[rawPeer];
            var id   = reader.GetByte();

            if (!_messages.Handlers.TryGetValue(id, out var handler))
            {
                _log.LogWarning($"Received unknown message ({id}; {reader.AvailableBytes}B) from {peer}");
            }
            else
            {
                handler(_manager, peer, reader);
            }
        }
コード例 #26
0
ファイル: NetworkServer.cs プロジェクト: niqqq25/MultiJuice
    void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
    {
        MessageTypes messageType = (MessageTypes)reader.GetByte();

        switch (messageType)
        {
        case MessageTypes.ClientCommand:
            OnClientCommand(peer, reader);
            break;

        default:
            break;
        }
    }
コード例 #27
0
        private void ReceiveClientCommand(NetPacketReader reader, int clientNetId)
        {
            IClientCommand command = m_clientCommandDict[(NetworkToServerDataType)reader.GetByte()];

            if (command.m_DataType != NetworkToServerDataType.SET_POSITION)
            {
                Console.WriteLine("CC: " + command.m_DataType);
            }
            try {
                command.Execute(reader, clientNetId);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
コード例 #28
0
ファイル: Command.cs プロジェクト: nzgamer41/Tango
        /// <summary>
        /// This method is used to extract the command type from an incoming message
        /// and return the matching handler object.
        /// </summary>
        /// <param name="reader">The incoming packet including the command type byte.</param>
        /// <param name="handler">This returns the command handler object. May be null if the command was not found.</param>
        /// <param name="message">This returns the message byte array without the command type byte.</param>
        public static void Parse(NetPacketReader reader, out CommandHandler handler, out byte[] message)
        {
            // The message type is the first byte, (255 message types)
            byte messageType = reader.GetByte();

            // Skip the first byte
            message = reader.GetRemainingBytes();

            if (!_handlerMapping.TryGetValue(messageType, out handler))
            {
                _logger.Error($"Command {messageType} not found!");
                return;
            }
        }
コード例 #29
0
 public void Decode(NetPacketReader im)
 {
     //Read Tilecount
     Tilecount = im.GetInt();
     //Create Array
     tiles = new Tile[(int)Math.Sqrt(Tilecount)][];
     for (int i = 0; i < tiles.Length; i++)
     {
         tiles[i] = new Tile[(int)Math.Sqrt(Tilecount)];
     }
     //Decode Tiles and put them into Array
     for (int i = 0; i < tiles.Length; i++)
     {
         for (int j = 0; j < tiles[0].Length; j++)
         {
             Faction  f        = (Faction)im.GetByte();
             int      p        = im.GetInt();
             TileType t        = (TileType)im.GetByte();
             Tile     tempTile = new Tile(f, p, t);
             tiles[i][j] = tempTile;
         }
     }
 }
コード例 #30
0
        public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            if (reader.RawData == null)
            {
                return;
            }

            //Console.WriteLine($"OnNetworkReceive: {reader.RawData.Length}");

            if (ConnectedClients.ContainsKey(peer.Id))
            {
                NetOperationCode operationCode = (NetOperationCode)reader.GetByte();

                ConnectedClients[peer.Id].NetworkReceive(operationCode, reader, deliveryMethod);
            }
        }