Beispiel #1
0
        public override void Client_ReceiveMessage(ByteStream data, LLClient client)
        {
            try
            {
                int     conId  = data.PopInt32();
                NetUser meUser = new NetUser()
                {
                    ConnectionID = conId,
                    UserName     = client.UserName,
                    TeamNumber   = client.TeamNumber
                };
                client.NetUsers[conId] = meUser;
                client.MyConnectionId  = conId;

                data = new ByteStream();
                data.Encode
                (
                    (byte)NetMessageType.USER_INFO,
                    meUser.UserName,
                    meUser.TeamNumber
                );
                // Send USER_INFO message
                client.SendNetMessage(client.ReliableChannel, data.ToArray());
                // Spawn own player instance and flag it
                client.PlayerInstances[meUser.ConnectionID]        = NetSpawner.SpawnPlayer(Vector3.zero, Quaternion.identity);
                client.PlayerInstances[meUser.ConnectionID].IsMine = true;
                // Inject the client
                client.PlayerInstances[meUser.ConnectionID].SetClient(client);
            }
            catch (Exception e)
            {
                Debug.LogError($"@Client -> @ConnectionAck: [{e.Message}]");
            }
        }
Beispiel #2
0
        public override void Client_ReceiveMessage(ByteStream data, LLClient client)
        {
            try
            {
                int    conId    = data.PopInt32();
                string userName = data.PopString();
                int    teamNum  = data.PopInt32();

                var newUser = new NetUser()
                {
                    ConnectionID = conId,
                    UserName     = userName,
                    TeamNumber   = teamNum
                };
                client.NetUsers[conId]        = newUser;
                client.PlayerInstances[conId] = NetSpawner.SpawnPlayer(Vector3.zero, Quaternion.identity);
            }
            catch (Exception e)
            {
                Debug.LogError($"@Client -> @OnUserInfo: [{e.Message}]");
            }
        }
Beispiel #3
0
        public override void Client_ReceiveMessage(ByteStream data, LLClient client)
        {
            try
            {
                int        conId    = data.PopInt32();
                string     userName = data.PopString();
                int        teamNum  = data.PopInt32();
                Vector3    pos      = data.PopVector3();
                Quaternion rot      = data.PopQuaternion();

                var newUser = new NetUser()
                {
                    ConnectionID = conId,
                    UserName     = userName,
                    TeamNumber   = teamNum
                };
                client.NetUsers[newUser.ConnectionID]        = newUser;
                client.PlayerInstances[newUser.ConnectionID] = NetSpawner.SpawnPlayer(pos, rot);
            }
            catch (Exception e)
            {
                Debug.LogError($"@Client -> @OnUserInfo_SpawnPosition: [{e.Message}]");
            }
        }
Beispiel #4
0
        private void OnConnectedToServer(int connectionId)
        {
            if (NetUsers.ContainsKey(connectionId))
            {
                Debug.Log($"@OnConnectedToServer -> userId [{connectionId}] has Re-Connected");
            }
            else
            {
                NetUser newUser = new NetUser()
                {
                    ConnectionID = connectionId
                };
                NetUsers[connectionId] = newUser;
                Debug.Log($"@OnConnectedToServer -> UserId[{connectionId}]");
            }
            // Send CONNECTION_ACK with the connectionId to the client
            ByteStream bytestream = new ByteStream();

            bytestream.Append((byte)NetMessageType.CONNECTION_ACK);
            bytestream.Append(connectionId);
            SendNetMessage(connectionId, ReliableChannel, bytestream.ToArray());
            // Spawn a player instance that represents the new user
            PlayerInstances[connectionId] = NetSpawner.SpawnPlayer(Vector3.zero, Quaternion.identity);
        }