public static void UpdateEntityPosition(string _guid, r_Vector3 _position)
 {
     if (m_WorldObjects.ContainsKey(_guid))
     {
         m_WorldObjects[_guid].m_Position = _position;
     }
 }
        public r_WorldObject(string _prefab, r_Vector3 _position, r_Quaternion _rotation, EntityType _entityType)
        {
            this.m_Prefab = _prefab;

            this.m_Position = _position;
            this.m_Rotation = _rotation;

            this.m_EntityType = _entityType;
        }
예제 #3
0
        public static void HandleEntityUpdate(int _connectionID, byte[] _data)
        {
            r_ByteBuffer _buffer = new r_ByteBuffer();

            _buffer.WriteBytes(_data);

            int    _packetID = _buffer.ReadInteger();
            string _guid     = _buffer.ReadString();

            r_Vector3 _position = new r_Vector3(_buffer.ReadFloat(), _buffer.ReadFloat(), _buffer.ReadFloat());

            _buffer.Dispose();

            r_WorldManager.UpdateEntityPosition(_guid, _position);
        }
        public void Update()
        {
            if (r_ClientManager.m_Clients.Count > 0)
            {
                if (GetClosestTarget() == null)
                {
                    return;
                }

                r_Client _target = GetClosestTarget();

                m_TargetPosition = _target.m_Position;
            }

            if (r_ClientManager.m_Clients.Count > 0)
            {
                r_SendWorldPacket.SendWorldObjectUpdateToClient(this.m_GUID, this.m_TargetPosition, this.m_Rotation, this.m_EntityType);
            }
        }
        /// <summary>
        /// Handles the player's position and rotation update
        /// </summary>
        public static void HandlePlayerUpdate(int _index, r_Vector3 _position, r_Quaternion _rotation)
        {
            r_ByteBuffer _buffer = new r_ByteBuffer();

            _buffer.WriteInteger((int)ServerPackets.UpdatePlayer);
            _buffer.WriteInteger(_index);

            _buffer.WriteFloat(_position.x);
            _buffer.WriteFloat(_position.y);
            _buffer.WriteFloat(_position.z);

            _buffer.WriteFloat(_rotation.x);
            _buffer.WriteFloat(_rotation.y);
            _buffer.WriteFloat(_rotation.z);
            _buffer.WriteFloat(_rotation.w);

            r_ClientManager.SendDataToAll(_buffer.ToArray());

            _buffer.Dispose();
        }
        public static void HandlePlayerUpdate(int _connectionID, byte[] _data)
        {
            r_ByteBuffer _buffer = new r_ByteBuffer();

            _buffer.WriteBytes(_data);

            int _packetID = _buffer.ReadInteger();

            r_Vector3    _position = new r_Vector3(_buffer.ReadFloat(), _buffer.ReadFloat(), _buffer.ReadFloat());
            r_Quaternion _rotation = new r_Quaternion(_buffer.ReadFloat(), _buffer.ReadFloat(), _buffer.ReadFloat(), _buffer.ReadFloat());

            _buffer.Dispose();

            if (r_ClientManager.m_Clients.ContainsKey(_connectionID))
            {
                r_ClientManager.m_Clients[_connectionID].m_Position = _position;
                r_ClientManager.m_Clients[_connectionID].m_Rotation = _rotation;
            }

            r_ClientManager.UpdateNetworkPlayer(_connectionID, _position, _rotation);
        }
예제 #7
0
        public static void SendWorldObjectUpdateToClient(string _guid, r_Vector3 _position, r_Quaternion _rotation, EntityType _entityType)
        {
            r_ByteBuffer _ByteBuffer = new r_ByteBuffer();

            _ByteBuffer.WriteInteger((int)ServerPackets.UpdateEntity);

            _ByteBuffer.WriteString(_guid);

            _ByteBuffer.WriteFloat(_position.x);
            _ByteBuffer.WriteFloat(_position.y);
            _ByteBuffer.WriteFloat(_position.z);

            _ByteBuffer.WriteFloat(_rotation.x);
            _ByteBuffer.WriteFloat(_rotation.y);
            _ByteBuffer.WriteFloat(_rotation.z);
            _ByteBuffer.WriteFloat(_rotation.w);

            _ByteBuffer.WriteInteger((int)_entityType);

            r_ClientManager.SendDataToAll(_ByteBuffer.ToArray());

            _ByteBuffer.Dispose();
        }
예제 #8
0
        public static void SendWorldObjectsToClient(int _connectionID, string _prefab, string _guid, r_Vector3 _position, r_Quaternion _rotation, EntityType _entityType)
        {
            r_ByteBuffer _ByteBuffer = new r_ByteBuffer();

            _ByteBuffer.WriteInteger((int)ServerPackets.InstantiateWorldObjects);

            _ByteBuffer.WriteString(_prefab);
            _ByteBuffer.WriteString(_guid);

            _ByteBuffer.WriteFloat(_position.x);
            _ByteBuffer.WriteFloat(_position.y);
            _ByteBuffer.WriteFloat(_position.z);

            _ByteBuffer.WriteFloat(_rotation.x);
            _ByteBuffer.WriteFloat(_rotation.y);
            _ByteBuffer.WriteFloat(_rotation.z);
            _ByteBuffer.WriteFloat(_rotation.w);

            _ByteBuffer.WriteInteger((int)_entityType);

            r_ClientManager.SendDataTo(_connectionID, _ByteBuffer.ToArray());

            _ByteBuffer.Dispose();
        }
        public static void InitCommand(string _command)
        {
            string[] _args = SplitCommand(_command);

            if (_args.Length == 1)
            {
                if (_args[0] == "/help")
                {
                    r_Log.Command("/help");
                    r_Log.Command("/kick userid");
                    r_Log.Command("/players");
                    r_Log.Command("/getposition userid");
                    r_Log.Command("/getrotation userid");
                }
                else if (_args[0] == "/players")
                {
                    if (r_ClientManager.m_Clients.Count == 0)
                    {
                        r_Log.Command($"[PLAYERS] There is no clients connected!");
                        return;
                    }
                    else
                    {
                        foreach (var _client in r_ClientManager.m_Clients)
                        {
                            r_Log.Command($"[PLAYERS] UserID:{_client.Value.m_ConnectionID}");
                        }
                    }
                }
                else if (_args[0] == "/clear")
                {
                    Console.Clear();
                }
            }
            else if (_args.Length == 2)
            {
                if (_args[0] == "/kick")
                {
                    if (r_ClientManager.m_Clients.ContainsKey(int.Parse(_args[1])))
                    {
                        r_ClientManager.m_Clients[int.Parse(_args[1])].CloseConnection(false);
                        r_Log.Command($"[KICK] User {int.Parse(_args[1])} has been kicked!");
                    }
                    else
                    {
                        r_Log.Error("[KICK] Userid doesnt exist!");
                    }
                }
                else if (_args[0] == "/getposition")
                {
                    if (r_ClientManager.m_Clients.ContainsKey(int.Parse(_args[1])))
                    {
                        r_Vector3 _position = r_ClientManager.m_Clients[int.Parse(_args[1])].GetPosition();
                        r_Log.Command($"[POSITION] {_position.x},{_position.y},{_position.z}");
                    }
                    else
                    {
                        r_Log.Error("[POSITION] Userid doesnt exist!");
                    }
                }
                else if (_args[0] == "/getrotation")
                {
                    if (r_ClientManager.m_Clients.ContainsKey(int.Parse(_args[1])))
                    {
                        r_Quaternion _rotation = r_ClientManager.m_Clients[int.Parse(_args[1])].GetRotation();
                        r_Log.Command($"[ROTATION] {_rotation.x},{_rotation.y},{_rotation.z},{_rotation.w}");
                    }
                    else
                    {
                        r_Log.Error("[POSITION] Userid doesnt exist!");
                    }
                }
            }
        }
 public static void UpdateNetworkPlayer(int _connectionID, r_Vector3 _position, r_Quaternion _rotation)
 {
     r_SendPlayerPacket.HandlePlayerUpdate(_connectionID, _position, _rotation);
 }