Esempio n. 1
0
    public LocationUpdate(GameClient client, ReceivablePacket packet)
    {
        // Read data.
        float posX       = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        float posY       = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        float posZ       = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        float heading    = (float)packet.ReadDouble(); // TODO: Client WriteFloat
        int   animState  = packet.ReadShort();
        int   waterState = packet.ReadByte();

        // Update player location.
        Player         player   = client.GetActiveChar();
        LocationHolder location = player.GetLocation();

        location.SetX(posX);
        location.SetY(posY);
        location.SetZ(posZ);
        location.SetHeading(heading);

        // Broadcast movement.
        foreach (Player nearby in WorldManager.GetVisiblePlayers(player))
        {
            nearby.ChannelSend(new MoveToLocation(player, heading, animState, waterState));
        }
    }
    public static void Handle(Player player)
    {
        LocationHolder location = player.GetLocation();

        // Send player success message.
        ChatManager.SendSystemMessage(player, "Your location is " + location.GetX() + " " + location.GetZ() + " " + location.GetY());
    }
    public static void Load()
    {
        ConfigReader accountConfigs = new ConfigReader(ACCOUNT_CONFIG_FILE);

        ACCOUNT_AUTO_CREATE    = accountConfigs.GetBool("AccountAutoCreate", false);
        ACCOUNT_MAX_CHARACTERS = accountConfigs.GetInt("AccountMaxCharacters", 5);

        ConfigReader loggingConfigs = new ConfigReader(LOGGING_CONFIG_FILE);

        LOG_CHAT  = loggingConfigs.GetBool("LogChat", true);
        LOG_WORLD = loggingConfigs.GetBool("LogWorld", true);

        ConfigReader playerConfigs = new ConfigReader(PLAYER_CONFIG_FILE);

        string[] startingLocation = playerConfigs.GetString("StartingLocation", "9945.9;9.2;10534.9").Split(";");
        STARTING_LOCATION = new LocationHolder(float.Parse(startingLocation[0], CultureInfo.InvariantCulture), float.Parse(startingLocation[1], CultureInfo.InvariantCulture), float.Parse(startingLocation[2], CultureInfo.InvariantCulture), startingLocation.Length > 3 ? float.Parse(startingLocation[3], CultureInfo.InvariantCulture) : 0);

        ConfigReader serverConfigs = new ConfigReader(SERVER_CONFIG_FILE);

        SERVER_PORT = serverConfigs.GetInt("ServerPort", 5055);
        DATABASE_CONNECTION_PARAMETERS = serverConfigs.GetString("DbConnectionParameters", "Server=127.0.0.1;User ID=root;Password=;Database=edws");
        DATABASE_MAX_CONNECTIONS       = serverConfigs.GetInt("MaximumDbConnections", 50);
        MAXIMUM_ONLINE_USERS           = serverConfigs.GetInt("MaximumOnlineUsers", 2000);
        CLIENT_VERSION = serverConfigs.GetDouble("ClientVersion", 1.0);

        LogManager.Log("Configs: Initialized.");
    }
        private static List <LocationHolder> GetAllLocations()
        {
            List <LocationHolder> locationHolders = new List <LocationHolder>();

            LocationsService locations = ServiceLocator.Instance.GetService <LocationsService>();
            var items = locations.Items;

            foreach (var item in items)
            {
                if (item.Location.LatitudeLongitude == null)
                {
                    continue;
                }

                var lh = new LocationHolder
                {
                    Location     = item.Location.LatitudeLongitude.Location,
                    FilmName     = item.Location.Name,
                    FilmSiteLink = $"{item.ImageFolder}/index.html"
                };
                locationHolders.Add(lh);
            }

            return(locationHolders);
        }
Esempio n. 5
0
 private void Awake()
 {
     //  StartCoroutine(MoveTowardsThis(0));
     sChecker  = GameObject.Find("Game_manager").GetComponent <StateChecker>();
     locHol    = gameObject.GetComponent <LocationHolder>();
     gridManag = GameObject.Find("Game_manager").GetComponent <GridManager>();
 }
    public static void HandleChat(Player sender, string message)
    {
        // Check if message is empty.
        message = message.Trim();
        if (message.Length == 0)
        {
            return;
        }

        string lowercaseMessage = message.ToLowerInvariant().Replace("\\s{2,}", " "); // Also remove all double spaces.

        if (lowercaseMessage.Equals(COMMAND_LOCATION))
        {
            LocationHolder location = sender.GetLocation();
            sender.ChannelSend(new ChatResult(CHAT_TYPE_SYSTEM, SYS_NAME, "Your location is " + location.GetX() + " " + location.GetY() + " " + location.GetZ()));
        }
        else if (lowercaseMessage.StartsWith(COMMAND_PERSONAL_MESSAGE))
        {
            string[] lowercaseMessageSplit = lowercaseMessage.Split(" ");
            if (lowercaseMessageSplit.Length < 3) // Check for parameters.
            {
                sender.ChannelSend(new ChatResult(CHAT_TYPE_SYSTEM, SYS_NAME, "Incorrect syntax. Use /tell [name] [message]."));
                return;
            }

            Player receiver = WorldManager.GetPlayerByName(lowercaseMessageSplit[1]);
            if (receiver == null)
            {
                sender.ChannelSend(new ChatResult(CHAT_TYPE_SYSTEM, SYS_NAME, "Player was not found."));
            }
            else
            {
                // Step by step cleanup, to avoid problems with extra/double spaces on original message.
                message = message.Substring(lowercaseMessageSplit[0].Length, message.Length).Trim(); // Remove command.
                message = message.Substring(lowercaseMessageSplit[1].Length, message.Length).Trim(); // Remove receiver name.
                sender.ChannelSend(new ChatResult(CHAT_TYPE_MESSAGE, MSG_TO + receiver.GetName(), message));
                receiver.ChannelSend(new ChatResult(CHAT_TYPE_MESSAGE, sender.GetName(), message));
                // Log chat.
                if (Config.LOG_CHAT)
                {
                    LogManager.LogChat("[" + sender.GetName() + "] to [" + receiver.GetName() + "] " + message);
                }
            }
        }
        else // Normal message.
        {
            sender.ChannelSend(new ChatResult(CHAT_TYPE_NORMAL, sender.GetName(), message));
            foreach (Player player in WorldManager.GetVisiblePlayers(sender))
            {
                player.ChannelSend(new ChatResult(CHAT_TYPE_NORMAL, sender.GetName(), message));
            }
            // Log chat.
            if (Config.LOG_CHAT)
            {
                LogManager.LogChat("[" + sender.GetName() + "] " + message);
            }
        }
    }
    public static void Handle(Player player)
    {
        // Gather information.
        WorldObject target = player.GetTarget();

        if (target == null)
        {
            ChatManager.SendSystemMessage(player, "You must select a target.");
            return;
        }
        Npc npc = target.AsNpc();

        if (npc == null)
        {
            ChatManager.SendSystemMessage(player, "You must select an NPC.");
            return;
        }

        // Log admin activity.
        SpawnHolder    npcSpawn    = npc.GetSpawnHolder();
        LocationHolder npcLocation = npcSpawn.GetLocation();

        if (Config.LOG_ADMIN)
        {
            LogManager.LogAdmin(player.GetName() + " used command /delete " + npc + " " + npcLocation);
        }

        // Delete NPC.
        npc.DeleteMe();

        // Send player success message.
        int npcId = npc.GetNpcHolder().GetNpcId();

        ChatManager.SendSystemMessage(player, "You have deleted " + npcId + " from " + npcLocation);

        // Store in database.
        try
        {
            MySqlConnection con = DatabaseManager.GetConnection();
            MySqlCommand    cmd = new MySqlCommand(SPAWN_DELETE_QUERY, con);
            cmd.Parameters.AddWithValue("npc_id", npcId);
            cmd.Parameters.AddWithValue("x", npcLocation.GetX());
            cmd.Parameters.AddWithValue("y", npcLocation.GetY());
            cmd.Parameters.AddWithValue("z", npcLocation.GetZ());
            cmd.Parameters.AddWithValue("heading", npcLocation.GetHeading());
            cmd.Parameters.AddWithValue("respawn_delay", npcSpawn.GetRespawnDelay());
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception e)
        {
            LogManager.Log(e.ToString());
        }
    }
    public void SetLocation(LocationHolder location)
    {
        this.location = location;

        // When changing location test for appropriate region.
        RegionHolder testRegion = WorldManager.GetRegion(this);

        if (!testRegion.Equals(region))
        {
            if (region != null)
            {
                // Remove this object from the region.
                region.RemoveObject(objectId);

                // Broadcast change to players left behind when teleporting.
                if (isTeleporting)
                {
                    DeleteObject deleteObject = new DeleteObject(this);
                    foreach (RegionHolder nearbyRegion in region.GetSurroundingRegions())
                    {
                        foreach (WorldObject obj in region.GetObjects())
                        {
                            if (obj == this)
                            {
                                continue;
                            }
                            if (obj.IsPlayer())
                            {
                                obj.AsPlayer().ChannelSend(deleteObject);
                            }
                        }
                    }
                }
            }

            // Assign new region.
            region = testRegion;
            region.AddObject(this);

            // Send visible NPC information.
            // TODO: Exclude known NPCs?
            if (IsPlayer())
            {
                foreach (WorldObject obj in WorldManager.GetVisibleObjects(this))
                {
                    if (!obj.IsNpc())
                    {
                        continue;
                    }
                    AsPlayer().ChannelSend(new NpcInformation(obj.AsNpc()));
                }
            }
        }
    }
Esempio n. 9
0
        private static void GetTravelPath()
        {
            var rand           = new Random();
            var startTesseract = _penteract.Tesseracts[rand.Next(_penteract.Tesseracts.Count - 1)];
            var startCube      = startTesseract.Cubes[rand.Next(startTesseract.Cubes.Count - 1)];

            _start = new LocationHolder(startTesseract, startCube);

            rand = new Random();
            var endTesseract = _penteract.Tesseracts[rand.Next(_penteract.Tesseracts.Count - 1)];
            var endCube      = endTesseract.Cubes[rand.Next(endTesseract.Cubes.Count - 1)];

            _end = new LocationHolder(endTesseract, endCube);
        }
    public static void Handle(Player player)
    {
        LocationHolder location = player.GetLocation();

        // Send player success message.
        StringBuilder sb = new StringBuilder();

        sb.Append("Your location is ");
        sb.Append(location.GetX());
        sb.Append(" ");
        sb.Append(location.GetZ());
        sb.Append(" ");
        sb.Append(location.GetY());
        ChatManager.SendSystemMessage(player, sb.ToString());
    }
    public void StructWithinTable()
    {
        LocationHolder holder = new LocationHolder
        {
            Fake     = "foobar",
            Location = new Location {
                X = 1.1f, Y = 1.2f, Z = 1.3f
            },
            LocationVector = new[]
            {
                new Location {
                    X = 2, Y = 3, Z = 4,
                },
                new Location {
                    X = 5, Y = 6, Z = 7,
                },
                new Location {
                    X = 8, Y = 9, Z = 10,
                }
            },
        };

        Span <byte> memory = new byte[10240];
        int         size   = FlatBufferSerializer.Default.Serialize(holder, memory);

        var oracle = Oracle.LocationHolder.GetRootAsLocationHolder(
            new FlatBuffers.ByteBuffer(memory.Slice(0, size).ToArray()));

        Assert.Equal(holder.Fake, oracle.Fake);

        Assert.Equal(holder.Location.X, oracle.SingleLocation.Value.X);
        Assert.Equal(holder.Location.Y, oracle.SingleLocation.Value.Y);
        Assert.Equal(holder.Location.Z, oracle.SingleLocation.Value.Z);

        Assert.Equal(holder.LocationVector.Count, oracle.LocationVectorLength);

        for (int i = 0; i < holder.LocationVector.Count; ++i)
        {
            var holderLoc = holder.LocationVector[i];
            var oracleLoc = oracle.LocationVector(i);

            Assert.Equal(holderLoc.X, oracleLoc.Value.X);
            Assert.Equal(holderLoc.Y, oracleLoc.Value.Y);
            Assert.Equal(holderLoc.Z, oracleLoc.Value.Z);
        }
    }
    public static Npc SpawnNpc(int npcId, LocationHolder location, int respawnDelay)
    {
        NpcHolder   npcHolder = NpcData.GetNpcHolder(npcId);
        SpawnHolder spawn     = new SpawnHolder(location, respawnDelay);
        Npc         npc       = null;

        switch (npcHolder.GetNpcType())
        {
        case NpcType.NPC:
            npc = new Npc(npcHolder, spawn);
            break;

        case NpcType.MONSTER:
            npc = new Monster(npcHolder, spawn);
            break;
        }
        return(npc);
    }
Esempio n. 13
0
 public SpawnHolder(LocationHolder location, int respawnDelay)
 {
     this.location     = location;
     this.respawnDelay = respawnDelay;
 }
 public void SetLocation(LocationHolder location)
 {
     this.location = location;
 }
    public static void Handle(Player player, string command)
    {
        // Gather information from parameters.
        string[] commandSplit = command.Split(' ');
        int      npcId;

        if (commandSplit.Length > 1)
        {
            npcId = int.Parse(commandSplit[1]);
        }
        else
        {
            ChatManager.SendSystemMessage(player, "Proper syntax is /spawn npcId delaySeconds(optional).");
            return;
        }
        int respawnDelay = 60;

        if (commandSplit.Length > 2)
        {
            respawnDelay = int.Parse(commandSplit[2]);
        }

        // Log admin activity.
        LocationHolder playerLocation = player.GetLocation();
        LocationHolder npcLocation    = new LocationHolder(playerLocation.GetX(), playerLocation.GetY(), playerLocation.GetZ(), playerLocation.GetHeading());

        if (Config.LOG_ADMIN)
        {
            LogManager.LogAdmin(player.GetName() + " used command /spawn " + npcId + " " + respawnDelay + " at " + npcLocation);
        }

        // Spawn NPC.
        Npc npc = SpawnData.SpawnNpc(npcId, npcLocation, respawnDelay);

        // Broadcast NPC information.
        NpcInformation info = new NpcInformation(npc);

        player.ChannelSend(info);
        foreach (Player nearby in WorldManager.GetVisiblePlayers(player))
        {
            nearby.ChannelSend(info);
        }

        // Send player success message.
        ChatManager.SendSystemMessage(player, "You have spawned " + npcId + " at " + npcLocation);

        // Store in database.
        try
        {
            MySqlConnection con = DatabaseManager.GetConnection();
            MySqlCommand    cmd = new MySqlCommand(SPAWN_SAVE_QUERY, con);
            cmd.Parameters.AddWithValue("npc_id", npcId);
            cmd.Parameters.AddWithValue("x", npcLocation.GetX());
            cmd.Parameters.AddWithValue("y", npcLocation.GetY());
            cmd.Parameters.AddWithValue("z", npcLocation.GetZ());
            cmd.Parameters.AddWithValue("heading", npcLocation.GetHeading());
            cmd.Parameters.AddWithValue("respawn_delay", respawnDelay);
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception e)
        {
            LogManager.Log(e.ToString());
        }
    }
 public void SetLocation(LocationHolder location)
 {
     SetLocation(location.GetX(), location.GetY(), location.GetZ(), location.GetHeading());
 }
Esempio n. 17
0
    public static void Load()
    {
        Util.PrintSection("Configs");

        // Initialize first so we can use logs as configured.
        ConfigReader loggingConfigs = new ConfigReader(LOGGING_CONFIG_FILE);

        LOG_FILE_SIZE_LIMIT_ENABLED = loggingConfigs.GetBool("LogFileSizeLimitEnabled", false);
        LOG_FILE_SIZE_LIMIT         = loggingConfigs.GetLong("LogFileSizeLimit", 1073741824);
        LOG_CHAT  = loggingConfigs.GetBool("LogChat", true);
        LOG_WORLD = loggingConfigs.GetBool("LogWorld", true);
        LOG_ADMIN = loggingConfigs.GetBool("LogAdmin", true);

        ConfigReader accountConfigs = new ConfigReader(ACCOUNT_CONFIG_FILE);

        ACCOUNT_AUTO_CREATE    = accountConfigs.GetBool("AccountAutoCreate", false);
        ACCOUNT_MAX_CHARACTERS = accountConfigs.GetInt("AccountMaxCharacters", 5);

        ConfigReader databaseConfigs = new ConfigReader(DATABASE_CONFIG_FILE);

        DATABASE_CONNECTION_PARAMETERS = databaseConfigs.GetString("DbConnectionParameters", "Server=127.0.0.1;User ID=root;Password=;Database=edws");
        DATABASE_MAX_CONNECTIONS       = databaseConfigs.GetInt("MaximumDbConnections", 50);

        ConfigReader networkConfigs = new ConfigReader(NETWORK_CONFIG_FILE);

        SERVER_PORT               = networkConfigs.GetInt("ServerPort", 5055);
        MAXIMUM_ONLINE_USERS      = networkConfigs.GetInt("MaximumOnlineUsers", 2000);
        CLIENT_VERSION            = networkConfigs.GetDouble("ClientVersion", 1.0);
        ENCRYPTION_SECRET_KEYWORD = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(networkConfigs.GetString("SecretKeyword", "SECRET_KEYWORD")));

        ConfigReader playerConfigs = new ConfigReader(PLAYER_CONFIG_FILE);

        string[] startingLocation = playerConfigs.GetString("StartingLocation", "3924.109;67.42678;2329.238").Split(";");
        STARTING_LOCATION = new LocationHolder(float.Parse(startingLocation[0], CultureInfo.InvariantCulture), float.Parse(startingLocation[1], CultureInfo.InvariantCulture), float.Parse(startingLocation[2], CultureInfo.InvariantCulture), startingLocation.Length > 3 ? float.Parse(startingLocation[3], CultureInfo.InvariantCulture) : 0);
        STARTING_ITEMS.Clear();
        foreach (string itemString in playerConfigs.GetString("StartingItems", "").Split(";"))
        {
            string trimmedString = itemString.Trim();
            if (!trimmedString.Equals(""))
            {
                int itemId = int.Parse(trimmedString);
                if (itemId > 0)
                {
                    STARTING_ITEMS.Add(itemId);
                }
            }
        }
        VALID_SKIN_COLORS.Clear();
        foreach (string colorCode in playerConfigs.GetString("ValidSkinColorCodes", "F1D1BD;F1C4AD;E7B79C;E19F7E;AF7152;7E472E;4A2410;F7DDC0;F3D1A9;C5775A;B55B44;863923;672818;3F1508").Split(";"))
        {
            VALID_SKIN_COLORS.Add(Util.HexStringToInt(colorCode));
        }

        ConfigReader worldConfigs = new ConfigReader(WORLD_CONFIG_FILE);

        WORLD_MINIMUM_X = worldConfigs.GetFloat("MinimumX", -558.8f);
        WORLD_MAXIMUM_X = worldConfigs.GetFloat("MaximumX", 4441.2f);
        WORLD_MINIMUM_Y = worldConfigs.GetFloat("MinimumY", -100f);
        WORLD_MAXIMUM_Y = worldConfigs.GetFloat("MaximumY", 1000f);
        WORLD_MINIMUM_Z = worldConfigs.GetFloat("MinimumZ", -1445.3f);
        WORLD_MAXIMUM_Z = worldConfigs.GetFloat("MaximumZ", 3554.7f);

        LogManager.Log("Configs: Initialized.");
    }
 public SpawnHolder(LocationHolder location, int respawnDelay)
 {
     _location     = location;
     _respawnDelay = respawnDelay;
 }
Esempio n. 19
0
        private static void Travel()
        {
            _current = _start;
            var inHyperCube = true;

            var traveled = new List <LocationHolder>();

            while (inHyperCube)
            {
                Console.Clear();
                Console.WriteLine($"Start:\t\t{_start}");
                Console.WriteLine($"End\t\t{_end}\n");
                Console.WriteLine($"Current:\t{_current}");

                var travelFacesString = "";
                traveled.Add(_current);
                var currentCubeFace       = _current.GetCube.Face;
                var currentTesseractFace  = _current.GetTesseract.Face;
                var oppositeCubeFace      = Face.GetOppositeFace(currentCubeFace);
                var oppositeTesseractFace = Face.GetOppositeFace(currentTesseractFace);

                var travelFaces = new List <Face>();
                travelFaces.AddRange(Face.Faces.Where
                                         (x => !(x.Equals(currentCubeFace) || x.Equals(oppositeCubeFace) ||
                                                 x.Equals(currentTesseractFace) ||
                                                 x.Equals(oppositeTesseractFace))));

                travelFacesString = travelFaces.ToArray().Aggregate(
                    travelFacesString, (current, travelFace) => current + (travelFace + " "));

                travelFacesString = travelFacesString.Trim();
                Console.WriteLine($"Travel Faces:\t{travelFacesString}");

                for (int k = 0; k < 6; k++)
                {
                    Console.WriteLine($"[{k+1}]:\t{travelFaces[k]}");
                }
                Console.WriteLine("[7]:\tFlip");
                Console.WriteLine("[8]:\tTravel Map");
                Console.WriteLine("[9]:\tExit (will NOT save progress");

                if (_current.Equals(_end))
                {
                    Console.WriteLine("[10]:\tYou've made it! Leave the hypercube.");
                }

                var  inRoom = true;
                Face face;
                while (inRoom)
                {
                    var choice = Console.ReadLine();
                    switch (choice)
                    {
                    case "1":
                        face     = travelFaces[0];
                        _current = new LocationHolder(_current.GetTesseract, new Cube(face));
                        inRoom   = false;
                        break;

                    case "2":
                        face     = travelFaces[1];
                        _current = new LocationHolder(_current.GetTesseract, new Cube(face));
                        inRoom   = false;
                        break;

                    case "3":
                        face     = travelFaces[2];
                        _current = new LocationHolder(_current.GetTesseract, new Cube(face));
                        inRoom   = false;
                        break;

                    case "4":
                        face     = travelFaces[3];
                        _current = new LocationHolder(_current.GetTesseract, new Cube(face));
                        inRoom   = false;
                        break;

                    case "5":
                        face     = travelFaces[4];
                        _current = new LocationHolder(_current.GetTesseract, new Cube(face));
                        inRoom   = false;
                        break;

                    case "6":
                        face     = travelFaces[5];
                        _current = new LocationHolder(_current.GetTesseract, new Cube(face));
                        inRoom   = false;
                        break;

                    case "7":
                        _current = new LocationHolder(new Tesseract(_current.GetCube.Face), new Cube(_current.GetTesseract.Face));
                        inRoom   = false;
                        break;

                    case "8":
                        var travelString = traveled.Aggregate("", (current, loc) => current + (loc + " "));

                        travelString = travelString.Trim();
                        Console.WriteLine($"Travel Path: {travelString}");
                        break;

                    case "9":
                        inRoom      = false;
                        inHyperCube = false;
                        break;

                    default:
                        if (_current.Equals(_end))
                        {
                            Console.WriteLine("Leaving the hypercube");
                            inRoom      = false;
                            inHyperCube = false;
                            break;
                        }
                        else
                        {
                            Console.WriteLine($"Oops! {choice} is not a choice. Please try again.");
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 20
0
 public List<DetectedLocationPathHolder> getPaths(LocationHolder get_me)
 {
     List<DetectedLocationPathHolder> return_me = new List<DetectedLocationPathHolder>();
     foreach(KeyValuePair<HandlerType,ALocationHandler> handler in handlers) {
         return_me.AddRange(handler.Value.getPaths(get_me));
     }
     return return_me;
 }