Ejemplo n.º 1
0
        public PlayerEntity(string name, ModelType modelType, Vector3 position, AuthoryServer server)
        {
            Server = server;


            Mana   = new Resource();
            Health = new Resource();

            Armor      = 300;
            Attributes = new int[Enum.GetValues(typeof(Attribute)).Length - 1];
            Buffs      = new List <Buff>(MAX_BUFF_COUNT);
            Skills     = new List <AbstractSkill>(20);

            EntityType = Entities.Enums.EntityType.Player;

            Name      = name;
            Uid       = new Random().Next(int.MaxValue);
            ModelType = modelType;

            Connection = null;

            Level = 99;
            SetStats();
            CalculateResources();
            Respawn();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends PlayerEntity info to master server for database save
        /// </summary>
        /// <param name="server">The MapServer where the player is</param>
        /// <param name="character">The player which information will be sent</param>
        private void SendBackCharacterInfo(AuthoryServer server, PlayerEntity character)
        {
            NetOutgoingMessage msgOut = masterClient.CreateMessage();

            msgOut.Write((byte)MasterMessageType.RequestCharacterInfo);
            msgOut.Write(CreateCharacterPacket(character));

            masterClient.SendMessage(msgOut, NetDeliveryMethod.ReliableOrdered);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends a message to MasterServer from character request to transfer to the specific map.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="character"></param>
        private void SendMapChangeRequest(AuthoryServer server, PlayerEntity character, int requestedMapIndex)
        {
            NetOutgoingMessage msgOut = masterClient.CreateMessage();

            msgOut.Write((byte)MasterMessageType.MapChangeRequest);

            msgOut.Write(requestedMapIndex);

            msgOut.Write(server.MapIndex);
            msgOut.Write(CreateCharacterPacket(character));

            masterClient.SendMessage(msgOut, NetDeliveryMethod.ReliableOrdered);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///Read messages from MasterServer
        /// </summary>
        private void ReadMaster()
        {
            NetIncomingMessage msgIn;
            MasterMessageType  msgType;

            while ((msgIn = masterClient.ReadMessage()) != null)
            {
                if (msgIn.MessageType == NetIncomingMessageType.Data)
                {
                    msgType = (MasterMessageType)msgIn.ReadByte();
                    Console.WriteLine(msgType.ToString());
                    switch (msgType)
                    {
                    case MasterMessageType.RequestMap:
                    {
                        int latestPort = msgIn.ReadInt32();


                        if (latestPort < 1000)
                        {
                            latestPort = (int)defaultServerPort++;
                        }

                        int    mapIndex = msgIn.ReadInt32();
                        string mapName  = msgIn.ReadString();
                        //int serverId = msgIn.ReadInt32();

                        AuthoryServer server = new AuthoryServer(MapServers.Count, defaultMapsFolderPath);
                        MapServers.Add(server);

                        Console.WriteLine("Requested port: " + latestPort);


                        server.Init(latestPort++, defaultAuthoryServerAuthString, mapName, mapIndex);
                        server.Start();



                        NetOutgoingMessage msgOut = masterClient.CreateMessage();

                        msgOut.Write((byte)MasterMessageType.MapCreated);

                        msgOut.Write(server.NetServer.Port);
                        msgOut.Write(server.MapIndex);
                        msgOut.Write(server.MapName);

                        masterClient.SendMessage(msgOut, NetDeliveryMethod.ReliableOrdered);

                        nodeUp = true;
                    }

                    break;

                    case MasterMessageType.RequestMaps:
                    {
                        int latestPort = msgIn.ReadInt32();

                        int infoCount = msgIn.ReadInt32();
                        for (int i = 0; i < infoCount; i++)
                        {
                            int    mapIndex = msgIn.ReadInt32();
                            string mapName  = msgIn.ReadString();

                            AuthoryServer server = new AuthoryServer(MapServers.Count, defaultMapsFolderPath);
                            MapServers.Add(server);

                            if (latestPort < 1000)
                            {
                                latestPort = (int)defaultServerPort++;
                            }

                            Console.WriteLine("Requested port: " + latestPort);

                            server.Init(latestPort++, defaultAuthoryServerAuthString, mapName, mapIndex);
                            server.Start();


                            NetOutgoingMessage msgOut = masterClient.CreateMessage();

                            msgOut.Write((byte)MasterMessageType.MapCreated);

                            msgOut.Write(server.NetServer.Port);
                            msgOut.Write(server.MapIndex);
                            msgOut.Write(server.MapName);

                            masterClient.SendMessage(msgOut, NetDeliveryMethod.ReliableOrdered);
                        }
                        nodeUp = true;
                    }
                    break;

                    case MasterMessageType.CharacterInfo:
                    {
                        int serverPort = msgIn.ReadInt32();

                        AuthoryServer mapServer = null;
                        foreach (var server in MapServers)
                        {
                            if (server.NetServer.Port == serverPort)
                            {
                                mapServer = server;
                            }
                        }

                        string accountName   = msgIn.ReadString();
                        string characterName = msgIn.ReadString();

                        int accountId   = msgIn.ReadInt32();
                        int characterId = msgIn.ReadInt32();

                        int health = msgIn.ReadInt32();
                        int mana   = msgIn.ReadInt32();

                        long      experience = msgIn.ReadInt64();
                        byte      level      = msgIn.ReadByte();
                        ModelType modelType  = (ModelType)msgIn.ReadByte();
                        float     posX       = msgIn.ReadFloat();
                        float     posZ       = msgIn.ReadFloat();

                        long uid = msgIn.ReadInt64();

                        PlayerEntity playerEntity = new PlayerEntity(characterName, modelType, level, new Vector3(posX, 0, posZ), null, mapServer, characterId, accountId);
                        playerEntity.Experience   = experience;
                        playerEntity.Health.Value = health;
                        playerEntity.Mana.Value   = mana;

                        Console.WriteLine(playerEntity);

                        playerEntity.SetId((ushort)(mapServer.Data.GetNextPlayerId()));

                        mapServer.Data.AwaitingConnections.TryAdd(uid, playerEntity);

                        NetOutgoingMessage msgOut = masterClient.CreateMessage();

                        msgOut.Write((byte)MasterMessageType.ConnectionApproved);
                        msgOut.Write(serverPort);
                        msgOut.Write(accountId);
                        msgOut.Write(characterId);
                        msgOut.Write(uid);
                        msgOut.Write(playerEntity.Id);


                        masterClient.SendMessage(msgOut, NetDeliveryMethod.ReliableOrdered);
                    }
                    break;

                    case MasterMessageType.RequestCharacterInfo:
                    {
                        int port        = msgIn.ReadInt32();
                        int characterId = msgIn.ReadInt32();

                        foreach (var server in MapServers)
                        {
                            foreach (var player in server.Data.PlayersById.Values)
                            {
                                if (player.CharacterId == characterId)
                                {
                                    SendBackCharacterInfo(server, player);
                                    return;
                                }
                            }
                            if (server.NetServer.Port == port)
                            {
                                if (server.Data.RecentlyOnlinePlayers.TryRemove(characterId, out PlayerEntity player))
                                {
                                    SendBackCharacterInfo(server, player);
                                    return;
                                }
                            }
                        }
                    }
                    break;

                    case MasterMessageType.Shutdown:
                    {
                        Shutdown();
                    }
                    break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public void ChangeMapServer(PlayerEntity player, AuthoryServer fromServer, int teleportToMapIndex)
 {
     fromServer.Data.FullRemovePlayer(player);
     SendMapChangeRequest(fromServer, player, teleportToMapIndex);
 }
Ejemplo n.º 6
0
        public PlayerEntity(string name, ModelType modelType, byte level, Vector3 position, NetConnection connection, AuthoryServer server, int characterId, int accountId)
        {
            this.Server = server;

            Mana   = new Resource();
            Health = new Resource();

            this.EntityType = Entities.Enums.EntityType.Player;

            this.CharacterId = characterId;
            this.AccountId   = accountId;

            this.Attributes = new int[Enum.GetValues(typeof(Attribute)).Length - 1];
            this.Buffs      = new List <Buff>(MAX_BUFF_COUNT);
            this.Skills     = new List <AbstractSkill>(20);

            this.Armor = 300;


            this.Name       = name;
            this.ModelType  = modelType;
            this.Position   = position;
            this.Connection = connection;

            this.Level = level;

            if (connection != null)
            {
                this.Uid = connection.RemoteUniqueIdentifier;
            }

            SetStats();
            CalculateResources();
            Respawn();
        }