예제 #1
0
        public override void Server_ReceiveMessage(int connectionID, ByteStream msgData, LLServer server)
        {
            string userName   = msgData.PopString();
            int    teamNumber = msgData.PopInt32();

            var netUser = new NetUser
            {
                connectionID = connectionID,
                userName     = userName,
                teamNumber   = teamNumber
            };

            server.NetUsers[connectionID] = netUser;

            var byteStream = new ByteStream();

            byteStream.Append((byte)NetMessageType.UserInfo);
            byteStream.Append(connectionID);
            byteStream.Append(userName);
            byteStream.Append(teamNumber);

            server.BroadcastNetMessage(server.ReliableChannel, byteStream.ToArray(), connectionID);

            byteStream.ResetBuffer();
            byteStream.Append((byte)NetMessageType.SpawnCharacter);
            byteStream.Append(connectionID);

            server.BroadcastNetMessage(server.ReliableChannel, byteStream.ToArray(), connectionID);


            foreach (var serverNetUser in server.NetUsers)
            {
                NetUser other = serverNetUser.Value;

                byteStream.ResetBuffer();

                byteStream.Append((byte)NetMessageType.UserInfo);
                byteStream.Append(other.connectionID);
                byteStream.Append(other.userName);
                byteStream.Append(other.teamNumber);

                server.SendNetMessage(connectionID, server.ReliableChannel, byteStream.ToArray());

                if (other.connectionID == connectionID)
                {
                    continue;
                }

                byteStream.ResetBuffer();
                byteStream.Append((byte)NetMessageType.SpawnCharacter);
                byteStream.Append(other.connectionID);

                server.SendNetMessage(connectionID, server.ReliableChannel, byteStream.ToArray());
            }
        }
예제 #2
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);
        }
예제 #3
0
 public override void Server_ReceiveMessage(int connectionId, ByteStream data, LLServer server)
 {
     try
     {
         data.Append(connectionId);
         server.BroadcastNetMessage(server.ReliableChannel, data.ToArray(), connectionId);
     }
     catch (Exception e)
     {
         Debug.LogError($"@Server -> @ChatBroadcast: [{e.Message}]");
     }
 }
예제 #4
0
        public override void Server_ReceiveMessage(int connectionId, ByteStream data, LLServer server)
        {
            try
            {
                // Update Current user Data
                var meUser = server.NetUsers[connectionId];
                meUser.UserName   = data.PopString();
                meUser.TeamNumber = data.PopInt32();

                ByteStream msg = new ByteStream();
                msg.Encode
                (
                    (byte)NetMessageType.USER_INFO,
                    connectionId,
                    meUser.UserName,
                    meUser.TeamNumber
                );

                // Broadcast this user info to other users
                server.BroadcastNetMessage(server.ReliableChannel, msg.ToArray(), connectionId);

                // Send currently connected users data to this user
                // The message here include the position and rotation to proper spawn the player
                foreach (var user in server.NetUsers)
                {
                    if (user.Key == connectionId)
                    {
                        continue;
                    }
                    msg = new ByteStream();
                    msg.Encode
                    (
                        (byte)NetMessageType.USER_INFO_SPAWNPOSITION,
                        user.Key,
                        user.Value.UserName,
                        user.Value.TeamNumber,
                        server.PlayerInstances[user.Key].transform.position,
                        server.PlayerInstances[user.Key].transform.rotation
                    );
                    server.SendNetMessage(connectionId, server.ReliableChannel, msg.ToArray());
                }
                Debug.Log($"@Server -> @UserInfo: User [ID: {connectionId} , UN:{meUser.UserName} , T:{meUser.TeamNumber} ] Registered");
            }
            catch (Exception e)
            {
                Debug.LogError($"@Server -> @OnUserInfo: [{e.Message}]");
            }
        }
예제 #5
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);
        }
예제 #6
0
        public override void Server_ReceiveMessage(int connectionId, ByteStream data, LLServer server)
        {
            try
            {
                // Get the destination vector and set on the right player instance
                Vector3 destination = data.PopVector3();
                server.PlayerInstances[connectionId].SetDestination(destination);

                data = new ByteStream();
                data.Encode
                (
                    (byte)NetMessageType.GAMEPLAY_SETDESTINATION,
                    connectionId,
                    destination
                );
                // Broadcast this user info to other users
                server.BroadcastNetMessage(server.ReliableChannel, data.ToArray(), connectionId);
            }
            catch (Exception e)
            {
                Debug.LogError($"@Client -> @ConnectionAck: [{e.Message}]");
            }
        }