Пример #1
0
    void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod delMethod)
    {
        if (reader.RawData == null)
        {
            return;
        }

        Debug.Log("Client || OnNetworkReceive: " + reader.RawData.Length);

        if (reader.RawData.Length >= 4)
        {
            NetworkTags netTag = (NetworkTags)reader.GetInt();

            if (netTag == NetworkTags.PlayerPositionsArray)
            {
                int lengthArray = (reader.RawData.Length - 4) / (sizeof(long) + sizeof(float) * 3);

                Debug.Log("Client || Positions array data num: " + lengthArray);

                for (int i = 0; i < lengthArray; i++)
                {
                    long playerId = reader.GetLong();

                    if (!netDictionary.ContainsKey(playerId))
                    {
                        netDictionary.Add(playerId, new NetPlayer());
                    }

                    netDictionary[playerId].Z = reader.GetFloat();
                }
            }
        }
    }
Пример #2
0
    public static LNSCreateRoomParameters FromReader(NetPacketReader reader)
    {
        if (reader.AvailableBytes > 0)
        {
            LNSCreateRoomParameters o = new LNSCreateRoomParameters();
            try
            {
                o.isPublic = reader.GetBool();
                if (reader.GetBool())
                {
                    o.password = reader.GetString();
                }


                o.filters           = LNSJoinRoomFilter.FromReader(reader);
                o.maxPlayers        = reader.GetInt();
                o.isQuadTreeAllowed = reader.GetBool();
                if (o.isQuadTreeAllowed)
                {
                    Rect bounds = new Rect(reader.GetFloat(), reader.GetFloat(), reader.GetFloat(), reader.GetFloat());
                    //bounds.center = new Vector2, reader.GetFloat());

                    o.quadTreeBounds = bounds;
                }
                o.idleLife = reader.GetLong();
            }
            catch
            {
                o.isQuadTreeAllowed = false;
            }
            return(o);
        }
        return(null);
    }
        public static NewCharacterDBPacket Read(NetPacketReader message)
        {
            var facCount = (int)message.GetVariableUInt32();
            var factions = new List <NewCharFaction>(facCount);

            for (int i = 0; i < facCount; i++)
            {
                factions.Add(new NewCharFaction()
                {
                    Nickname = message.GetString(),
                    RepGroup = message.GetString(),
                    Base     = message.GetString(),
                    Package  = message.GetString(),
                    Pilot    = message.GetString()
                });
            }
            var pkgCount = (int)message.GetVariableUInt32();
            var packages = new List <NewCharPackage>(pkgCount);

            for (int i = 0; i < pkgCount; i++)
            {
                packages.Add(new NewCharPackage()
                {
                    Nickname  = message.GetString(),
                    StridName = message.GetInt(),
                    StridDesc = message.GetInt(),
                    Ship      = message.GetString(),
                    Loadout   = message.GetString(),
                    Money     = message.GetLong()
                });
            }
            var pilotCount = (int)message.GetVariableUInt32();
            var pilots     = new List <NewCharPilot>(pilotCount);

            for (int i = 0; i < pilotCount; i++)
            {
                pilots.Add(new NewCharPilot()
                {
                    Nickname = message.GetString(),
                    Body     = message.GetString(),
                    Comm     = message.GetString(),
                    Voice    = message.GetString(),
                    BodyAnim = message.GetString(),
                    CommAnim = new string[] { message.GetString(), message.GetString() }
                });
            }
            return(new NewCharacterDBPacket()
            {
                Factions = factions,
                Packages = packages,
                Pilots = pilots
            });
        }
        public static AddCharacterPacket Read(NetPacketReader message)
        {
            var ac = new AddCharacterPacket();

            ac.Character          = new SelectableCharacter();
            ac.Character.Name     = message.GetString();
            ac.Character.Rank     = (int)message.GetVariableUInt32();
            ac.Character.Funds    = message.GetLong();
            ac.Character.Ship     = message.GetString();
            ac.Character.Location = message.GetString();
            return(ac);
        }
Пример #5
0
        private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            long    time    = reader.GetLong();
            LogType logType = (LogType)reader.GetInt();
            string  message = reader.GetString();

            //Debug.LogFormat("[{0}] {1} {2}", time, logType.ToString(),message);

            if (onLogReceived != null)
            {
                onLogReceived(time, logType, message);
            }
            reader.Recycle();
        }
Пример #6
0
    public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
    {
        if (reader.RawData == null)
        {
            return;
        }

        if (reader.RawData.Length >= 4)
        {
            NetworkTags networkTag = (NetworkTags)reader.GetInt();
            if (networkTag == NetworkTags.StartGame)
            {
                Debug.Log("[CLIENT] StartGame resieved");
                ball.gameObject.SetActive(true);
                if (id == 0)
                {
                    Destroy(ball.GetComponent <Ball>());
                }
            }
            else if (networkTag == NetworkTags.PlayerPositionsArray)
            {
                int lengthArr = (reader.RawData.Length - 4) / (sizeof(long) + sizeof(float) * 3);

                Debug.Log("Got positions array data num : " + lengthArr);

                for (int i = 0; i < lengthArr; i++)
                {
                    long playerid = reader.GetLong();

                    if (!netPlayersDictionary.ContainsKey(playerid))
                    {
                        netPlayersDictionary.Add(playerid, new NetPlayer());
                        id = (int)playerid;
                    }

                    netPlayersDictionary[playerid].X = reader.GetFloat();
                    netPlayersDictionary[playerid].Y = reader.GetFloat();
                    netPlayersDictionary[playerid].Z = reader.GetFloat();
                }
            }
            else if (networkTag == NetworkTags.BallPosition)
            {
                float x = reader.GetFloat();
                float y = reader.GetFloat();
                float z = reader.GetFloat();
                ball.transform.position = new Vector3(x, y, z);
            }
        }
    }
        public static OpenCharacterListPacket Read(NetPacketReader message)
        {
            var oc = new OpenCharacterListPacket();

            oc.Info                   = new CharacterSelectInfo();
            oc.Info.ServerName        = message.GetString();
            oc.Info.ServerDescription = message.GetString();
            oc.Info.ServerNews        = message.GetString();
            var charCount = (int)message.GetVariableUInt32();

            oc.Info.Characters = new List <SelectableCharacter>(charCount);
            for (int i = 0; i < charCount; i++)
            {
                var c = new SelectableCharacter();
                c.Name     = message.GetString();
                c.Rank     = (int)message.GetVariableUInt32();
                c.Funds    = message.GetLong();
                c.Ship     = message.GetString();
                c.Location = message.GetString();
                oc.Info.Characters.Add(c);
            }
            return(oc);
        }