public override void Server_ReceiveMessage(int connectionID, ByteStream msgData, LLServer server)
        {
            int    teamNumber = msgData.PopInt32();
            string message    = msgData.PopString();

            var targetsList = new List <int>();

            foreach (var userPair in server.NetUsers)
            {
                NetUser netUser = userPair.Value;

                if (netUser.teamNumber == teamNumber && netUser.connectionID != connectionID)
                {
                    targetsList.Add(netUser.connectionID);
                }
            }

            int[] targets = targetsList.ToArray();

            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.ChatTeamMessage);
            byteStream.Append(teamNumber);
            byteStream.Append(message);

            server.MulticastNetMessage(targets, server.ReliableChannel, byteStream.ToArray());
        }
        private void OnConnectedToServer(int recConnectionID)
        {
            if (netUsers.ContainsKey(recConnectionID))
            {
                Debug.Log($"@OnConnectedToServer => userId [{recConnectionID}] has Re-Connected");
            }
            else
            {
                var newUser = new NetUser
                {
                    connectionID = recConnectionID,
                    teamNumber   = teamNumber,
                    userName     = userName
                };

                myConnectionID            = recConnectionID;
                netUsers[recConnectionID] = newUser;

                SpawnMyCharacter();

                Debug.Log($"@Server.Receiver.Connect => userId [{recConnectionID}]");
            }

            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.ConnectionAck);
            byteStream.Append(netUsers[recConnectionID].userName);
            byteStream.Append(netUsers[recConnectionID].teamNumber);

            SendNetMessage(reliableChannel, byteStream.ToArray());
        }
Exemplo n.º 3
0
        public void ResetBuffer_Test()
        {
            var tmp = new ByteStream();

            tmp.Append(1);
            tmp.Append(2f);
            Assert.AreEqual(tmp.Length, 8);
            tmp.ResetBuffer();
            Assert.AreEqual(tmp.Length, 0);
        }
Exemplo n.º 4
0
        public void SetIndex_Test()
        {
            var tmp = new ByteStream();

            tmp.Append(1);
            tmp.Append(2f);
            tmp.Append(3);
            tmp.Index = 8;

            Assert.AreEqual(tmp.PopInt32(), 3);
        }
        /// <summary>
        /// Called whenever the local client clicks on the ground of the level
        /// </summary>
        /// <param name="targetPos"></param>
        private void OnCharacterMove(Vector3 targetPos)
        {
            netUsers[myConnectionID].targetPos = targetPos;

            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.CharacterMove);
            byteStream.Append(targetPos);

            SendNetMessage(reliableChannel, byteStream.ToArray());
        }
Exemplo n.º 6
0
        public void ResetIndex_Test()
        {
            var tmp = new ByteStream();

            tmp.Append(1);
            tmp.Append(2f);
            Assert.AreEqual(tmp.PopInt32(), 1);
            Assert.AreEqual(tmp.PopFloat(), 2f);
            tmp.Index = 0;
            Assert.AreEqual(tmp.PopInt32(), 1);
        }
Exemplo n.º 7
0
        public void GetLength_Tester()
        {
            var tmp = new ByteStream();

            tmp.Append(1);
            tmp.Append(2f);
            tmp.Append(true);
            Assert.AreEqual(tmp.Length, tmp.ToArray().Length);
            Assert.AreEqual(1, tmp.PopInt32());
            Assert.AreEqual(2f, tmp.PopFloat());
            Assert.AreEqual(true, tmp.PopBool());
        }
        public void DisconnectUser(int connectionID)
        {
            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.Disconnect);
            byteStream.Append(connectionID);

            NetUsers.Remove(connectionID);

            BroadcastNetMessage(ReliableChannel, byteStream.ToArray());
            NetworkTransport.Disconnect(socketId, connectionID, out byte error);
        }
Exemplo n.º 9
0
        public override void Server_ReceiveMessage(int connectionID, ByteStream msgData, LLServer server)
        {
            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.ChatBroadcast);

            string message = msgData.PopString();

            byteStream.Append(message);

            server.BroadcastNetMessage(server.ReliableChannel, byteStream.ToArray(), connectionID);
        }
Exemplo n.º 10
0
        public override void Server_ReceiveMessage(int connectionID, ByteStream msgData, LLServer server)
        {
            int    target  = msgData.PopInt32();
            string message = msgData.PopString();

            ByteStream byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.ChatWhisper);
            byteStream.Append(connectionID);
            byteStream.Append(message);

            server.SendNetMessage(target, server.ReliableChannel, byteStream.ToArray());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Sends the information to all clients of a character that requires to be moved
        /// </summary>
        /// <param name="connectionID"></param>
        /// <param name="msgData"></param>
        /// <param name="server"></param>
        public override void Server_ReceiveMessage(int connectionID, ByteStream msgData, LLServer server)
        {
            NetUser netUser = server.NetUsers[connectionID];

            netUser.targetPos = msgData.PopVector3();

            server.NetUsers[connectionID] = netUser;

            msgData.ResetBuffer();

            msgData.Append((byte)NetMessageType.CharacterMove);
            msgData.Append(connectionID);
            msgData.Append(netUser.targetPos);

            server.BroadcastNetMessage(server.ReliableChannel, msgData.ToArray(), connectionID);
        }
        private void OnApplicationQuit()
        {
            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.Disconnect);

            SendNetMessage(reliableChannel, byteStream.ToArray());
        }
Exemplo n.º 13
0
    public override void Server_ReceiveMessage(int connectionId, ByteStream msgData, LLServer server)
    {
        var targetId = msgData.PopInt32();

        msgData.Append(connectionId);

        server.SendNetMessage(targetId, server.ReliableChannel, msgData.ToArray());
    }
Exemplo n.º 14
0
        public void Load_Test()
        {
            var tmp = new ByteStream();

            tmp.Append(1);
            tmp.Append(2f);
            var clone = new ByteStream();

            clone.Load(tmp.ToArray());

            Assert.AreEqual(clone.PopInt32(), tmp.PopInt32());
            Assert.AreEqual(clone.PopFloat(), tmp.PopFloat());
            Assert.AreEqual(clone.Length, tmp.Length);

            tmp.Append(true);

            Assert.AreNotEqual(clone.Length, tmp.Length);
        }
Exemplo n.º 15
0
 public override void Server_ReceiveMessage(int connectionId, ByteStream data, LLServer server)
 {
     data.Append(connectionId);
     // Get all teammates
     int[] targets = server.NetUsers.Where(x => x.Value.TeamNumber == server.NetUsers[connectionId].TeamNumber)
                     .Select(x => x.Key)
                     .ToArray();
     server.MulticastNetMessage(targets, server.ReliableChannel, data.ToArray(), connectionId);
 }
Exemplo n.º 16
0
        public void DateTime_Test()
        {
            DateTime val = DateTime.UtcNow;
            var      tmp = new ByteStream();

            tmp.Append(val);
            var ret = tmp.PopDatetime();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 17
0
        public void String_Test()
        {
            string val = "HELLO";
            var    tmp = new ByteStream();

            tmp.Append(val);
            var ret = tmp.PopString();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 18
0
        public void Char_Test()
        {
            char val = 'A';
            var  tmp = new ByteStream();

            tmp.Append(val);
            var ret = tmp.PopChar();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 19
0
    private void AppendDemo()
    {
        //initialize object as empty
        var byteStream = new ByteStream();

        //Append parameters in order
        byteStream.Append(true);
        byteStream.Append(1);
        byteStream.Append(2f);
        byteStream.Append("Thsi is a string");

        print($"Byte Length -> {byteStream.Length}");

        //Pop and print from Byte stream in order
        print(byteStream.PopBool());
        print(byteStream.PopInt32());
        print(byteStream.PopFloat());
        print(byteStream.PopString());
    }
Exemplo n.º 20
0
        public void UInt16_Test()
        {
            UInt16 val = 2;
            var    tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, val);
            var ret = tmp.PopUInt16();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 21
0
        public void Byte_Test()
        {
            byte val = 1;
            var  tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, val);
            var ret = tmp.PopByte();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 22
0
        public void Int64_Test()
        {
            Int64 val = -8;
            var   tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, Math.Abs(val));
            var ret = tmp.PopInt64();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 23
0
        public void SByte_Test()
        {
            sbyte val = -1;
            var   tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, Math.Abs(val));
            var ret = tmp.PopSByte();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 24
0
        public void Quaternion_Test()
        {
            Quaternion val = Quaternion.identity;
            var        tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, 16);
            var ret = tmp.PopQuaternion();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 25
0
        public void Float_Test()
        {
            float val = 4;
            var   tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, val);
            var ret = tmp.PopFloat();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 26
0
    private void PrependDemo()
    {
        //initialize object as empty
        var byteStream = new ByteStream();

        //Append parameters in order
        byteStream.Append(true);
        byteStream.Append(2f);
        //Prepend a parameter
        byteStream.Prepend("Thsi is a Prepended String");
        byteStream.Prepend(1);

        print($"Byte Length -> {byteStream.Length}, Final order will be: [int, string, bool, float]");

        //Pop and print from Byte stream in order
        print(byteStream.PopInt32());
        print(byteStream.PopString());
        print(byteStream.PopBool());
        print(byteStream.PopFloat());
    }
Exemplo n.º 27
0
        public byte[] ToArray()
        {
            UpdateHeader();
            ByteStream result = new ByteStream(Size);

            result
            .Append(header.ToArray())
            .Append(questions.Select(q => q.ToArray()));

            return(result.ToArray());
        }
Exemplo n.º 28
0
        public void Bool_Test()
        {
            bool val = true;
            var  tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, 1);
            var ret = tmp.PopBool();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 29
0
        public void Double_Test()
        {
            double val = 8;
            var    tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, val);
            var ret = tmp.PopDouble();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 30
0
        public void Vector3_Test()
        {
            Vector3 val = Vector3.up;
            var     tmp = new ByteStream();

            tmp.Append(val);
            Assert.AreEqual(tmp.Length, 12);
            var ret = tmp.PopVector3();

            Assert.AreEqual(val, ret);
        }
Exemplo n.º 31
0
            public byte[] ToArray()
            {
                ByteStream result = new ByteStream(Size);

                result
                    .Append(domain.ToArray())
                    .Append(Marshalling.Struct.GetBytes(new Tail { Type = Type, Class = Class }));

                return result.ToArray();
            }