Example #1
0
        public void HandleGameRoomCreate(GSPacketIn pkg)
        {
            int roomId   = pkg.ReadInt();
            int gameType = pkg.ReadInt();
            int count    = pkg.ReadInt();

            IGamePlayer[] players = new IGamePlayer[count];
            for (int i = 0; i < count; i++)
            {
                PlayerInfo info = new PlayerInfo();
                info.ID      = pkg.ReadInt();
                info.Attack  = pkg.ReadInt();
                info.Defence = pkg.ReadInt();
                info.Agility = pkg.ReadInt();
                info.Luck    = pkg.ReadInt();

                double baseAttack  = pkg.ReadDouble();
                double baseDefence = pkg.ReadDouble();
                double baseAgility = pkg.ReadDouble();
                double baseBlood   = pkg.ReadDouble();
                int    templateId  = pkg.ReadInt();

                ItemTemplateInfo itemTemplate = ItemMgr.FindItemTemplate(templateId);
                ItemInfo         item         = new ItemInfo(itemTemplate);

                players[i] = new ProxyPlayer(info, item, baseAttack, baseDefence, baseAgility, baseBlood);
            }

            ProxyRoomMgr.CreateRoom(players, roomId, this);
        }
Example #2
0
        private void HandlePlayerExit(GSPacketIn pkg)
        {
            BaseGame game = GameMgr.FindGame(pkg.ClientID);

            if (game != null)
            {
                Player player = game.FindPlayer(pkg.Parameter1);
                if (player != null)
                {
                    GSPacketIn pkg1 = new GSPacketIn((byte)eFightPackageType.DISCONNECT, player.PlayerDetail.PlayerCharacter.ID);
                    game.SendToAll(pkg1);
                    game.RemovePlayer(player.PlayerDetail, false);

                    ProxyRoom room = ProxyRoomMgr.GetRoomUnsafe((game as BattleGame).Red.RoomId);
                    if (room != null)
                    {
                        if (!room.RemovePlayer(player.PlayerDetail))
                        {
                            ProxyRoom room1 = ProxyRoomMgr.GetRoomUnsafe((game as BattleGame).Blue.RoomId);
                            if (room1 != null)
                            {
                                room1.RemovePlayer(player.PlayerDetail);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        protected override void OnConnect()
        {
            base.OnConnect();
            this.m_rsa = new RSACryptoServiceProvider();
            RSAParameters para = this.m_rsa.ExportParameters(false);

            this.SendRSAKey(para.Modulus, para.Exponent);
            this.SendInfoToGameServer(ProxyRoomMgr.GetAllRoomCount(), ProxyRoomMgr.GetWaitingRoomCount(), CrossFightServer.Instance.Configuration.ServerType);
        }
Example #4
0
        public void HandleGameRoomCancel(GSPacketIn pkg)
        {
            ProxyRoom room = null;

            lock (m_rooms)
            {
                if (m_rooms.ContainsKey(pkg.Parameter1))
                {
                    room = m_rooms[pkg.Parameter1];
                }
            }

            if (room != null)
            {
                ProxyRoomMgr.RemoveRoom(room);
            }
        }
Example #5
0
 public override void Stop()
 {
     if (m_running == false)
     {
         return;
     }
     try
     {
         m_running = false;
         GameMgr.Stop();
         ProxyRoomMgr.Stop();
     }
     catch (Exception ex)
     {
         log.Error("Server stopp error:", ex);
     }
     finally
     {
         base.Stop();
     }
 }
Example #6
0
 public override void Stop()
 {
     if (this.m_running)
     {
         try
         {
             this.m_running = false;
             GameMgr.Stop();
             ProxyRoomMgr.Stop();
         }
         catch (Exception ex)
         {
             CrossFightServer.log.Error("Server stopp error:", ex);
         }
         finally
         {
             base.Stop();
         }
         CrossFightServer.log.Warn("Fight server is stopped!");
     }
 }
Example #7
0
 public override void Stop()
 {
     if (!this.m_running)
     {
         return;
     }
     try
     {
         this.m_running = false;
         GameMgr.Stop();
         ProxyRoomMgr.Stop();
     }
     catch (Exception exception)
     {
         FightServer.log.Error("Server stopp error:", exception);
     }
     finally
     {
         base.Stop();
     }
 }
Example #8
0
        public void HandleGameRoomCancel(GSPacketIn pkg)
        {
            ProxyRoom room = null;
            Dictionary <int, ProxyRoom> rooms;

            Monitor.Enter(rooms = this.m_rooms);
            try
            {
                if (this.m_rooms.ContainsKey(pkg.Parameter1))
                {
                    room = this.m_rooms[pkg.Parameter1];
                }
            }
            finally
            {
                Monitor.Exit(rooms);
            }
            if (room != null)
            {
                ProxyRoomMgr.RemoveRoom(room);
            }
        }
Example #9
0
        private void HandlerPickUpNPC(GSPacketIn pkg)
        {
            int       roomid = pkg.ReadInt();
            ProxyRoom room   = null;
            Dictionary <int, ProxyRoom> rooms;

            Monitor.Enter(rooms = this.m_rooms);
            try
            {
                if (this.m_rooms.ContainsKey(roomid))
                {
                    room = this.m_rooms[roomid];
                }
            }
            finally
            {
                Monitor.Exit(rooms);
            }
            if (room != null && room.PickUpCount >= 2)
            {
                Console.WriteLine("可以撮合NPC");
                ProxyRoomMgr.FightWithNPC(room);
            }
        }
Example #10
0
        private void HandlePlayerExit(GSPacketIn pkg)
        {
            BaseGame baseGame = GameMgr.FindGame(pkg.ClientID);

            if (baseGame != null)
            {
                Player player = baseGame.FindPlayer(pkg.Parameter1);
                if (player != null)
                {
                    GSPacketIn pkg2 = new GSPacketIn(83, player.PlayerDetail.PlayerCharacter.ID);
                    baseGame.SendToAll(pkg2);
                    baseGame.RemovePlayer(player.PlayerDetail, false);
                    ProxyRoom roomUnsafe = ProxyRoomMgr.GetRoomUnsafe((baseGame as BattleGame).Red.RoomId);
                    if (roomUnsafe != null && !roomUnsafe.RemovePlayer(player.PlayerDetail))
                    {
                        ProxyRoom roomUnsafe2 = ProxyRoomMgr.GetRoomUnsafe((baseGame as BattleGame).Blue.RoomId);
                        if (roomUnsafe2 != null)
                        {
                            roomUnsafe2.RemovePlayer(player.PlayerDetail);
                        }
                    }
                }
            }
        }
Example #11
0
        public override bool Start()
        {
            if (m_running)
            {
                return(false);
            }
            try
            {
                m_running = true;

                Thread.CurrentThread.Priority = ThreadPriority.Normal;

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                //初始化监听端口
                if (!InitComponent(InitSocket(m_config.Ip, m_config.Port), "InitSocket Port:" + m_config.Port))
                {
                    return(false);
                }

                //初始化脚本
                if (!InitComponent(StartScriptComponents(), "Script components"))
                {
                    return(false);
                }

                if (!InitComponent(ProxyRoomMgr.Setup(), "RoomMgr.Setup"))
                {
                    return(false);
                }

                if (!InitComponent(GameMgr.Setup(0, 4), "GameMgr.Setup"))
                {
                    return(false);
                }

                if (!InitComponent(MapMgr.Init(), "MapMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(ItemMgr.Init(), "ItemMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(PropItemMgr.Init(), "ItemMgr Init"))
                {
                    return(false);
                }

                //if (!InitComponent(VaneMgr.ByteAray(), "VaneMgr ByteAray"))
                //   return false;

                if (!InitComponent(BallMgr.Init(), "BallMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(BallConfigMgr.Init(), "BallConfigMgr Init"))
                {
                    return(false);
                }
                if (!InitComponent(DropMgr.Init(), "DropMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(NPCInfoMgr.Init(), "NPCInfoMgr Init"))
                {
                    return(false);
                }

                if (!InitComponent(LanguageMgr.Setup(@""), "LanguageMgr Init"))
                {
                    return(false);
                }

                //发布脚本已加载事件
                GameEventMgr.Notify(ScriptEvent.Loaded);

                if (!InitComponent(base.Start(), "base.Start()"))
                {
                    return(false);
                }

                ProxyRoomMgr.Start();
                GameMgr.Start();

                //发布服务器开始事件
                GameEventMgr.Notify(GameServerEvent.Started, this);

                GC.Collect(GC.MaxGeneration);

                log.Info("GameServer is now open for connections!");

                return(true);
            }
            catch (Exception e)
            {
                log.Error("Failed to start the server", e);
                return(false);
            }
        }
Example #12
0
        /// <summary>
        /// Handles the server action
        /// </summary>
        /// <param name="parameters"></param>
        public void OnAction(Hashtable parameters)
        {
            Console.WriteLine("This server DDTankII, edit and build by Trminhpc!");
            Console.WriteLine("Starting FightingServer ... please wait a moment!");

            FightServerConfig config = new FightServerConfig();

            try
            {
                config.Load();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                return;
            }

            FightServer.CreateInstance(config);
            FightServer.Instance.Start();

            bool run = true;

            while (run)
            {
                try
                {
                    Console.Write("> ");
                    string   line = Console.ReadLine();
                    string[] para = line.Split(' ');

                    switch (para[0].ToLower())
                    {
                    case "clear":
                        Console.Clear();
                        break;

                    case "list":
                        if (para.Length > 1)
                        {
                            switch (para[1])
                            {
                            case "-client":
                                Console.WriteLine("server client list:");
                                Console.WriteLine("--------------------");
                                ServerClient[] list = FightServer.Instance.GetAllClients();
                                foreach (ServerClient client in list)
                                {
                                    Console.WriteLine(client.ToString());
                                }
                                Console.WriteLine("-------------------");
                                break;

                            case "-room":
                                Console.WriteLine("room list:");
                                Console.WriteLine("-------------------------------");
                                ProxyRoom[] rooms = ProxyRoomMgr.GetAllRoom();
                                foreach (ProxyRoom room in rooms)
                                {
                                    Console.WriteLine(room.ToString());
                                }
                                Console.WriteLine("-------------------------------");
                                break;

                            case "-game":
                                Console.WriteLine("game list:");
                                Console.WriteLine("-------------------------------");
                                List <BaseGame> games = GameMgr.GetGames();
                                foreach (BaseGame g in games)
                                {
                                    Console.WriteLine(g.ToString());
                                }
                                Console.WriteLine("-------------------------------");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("list [-client][-room][-game]");
                            Console.WriteLine("     -client:列出所有服务器对象");
                            Console.WriteLine("     -room:列出所有房间对象");
                            Console.WriteLine("     -game:列出所有游戏对象");
                        }

                        break;

                    case "exit":
                        run = false;
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error:" + ex.ToString());
                }
            }

            if (FightServer.Instance != null)
            {
                FightServer.Instance.Stop();
            }
        }
Example #13
0
        public void HandleGameRoomCreate(GSPacketIn pkg)
        {
            int  totalLevel      = 0;
            int  totalFightPower = 0;
            int  roomId          = pkg.ReadInt();
            int  gameType        = pkg.ReadInt();
            int  guildId         = pkg.ReadInt();
            int  areaId          = pkg.ReadInt();
            bool IsArea          = pkg.ReadBoolean();
            int  count           = pkg.ReadInt();

            IGamePlayer[] players = new IGamePlayer[count];
            for (int i = 0; i < count; i++)
            {
                PlayerInfo      info            = new PlayerInfo();
                ProxyPlayerInfo proxyPlayerInfo = new ProxyPlayerInfo();
                proxyPlayerInfo.m_AreaID   = pkg.ReadInt();
                proxyPlayerInfo.m_AreaName = pkg.ReadString();
                info.ID              = pkg.ReadInt();
                info.NickName        = pkg.ReadString();
                info.Sex             = pkg.ReadBoolean();
                info.Hide            = pkg.ReadInt();
                info.Style           = pkg.ReadString();
                info.Colors          = pkg.ReadString();
                info.Skin            = pkg.ReadString();
                info.Offer           = pkg.ReadInt();
                info.GP              = pkg.ReadInt();
                info.Grade           = pkg.ReadInt();
                info.Repute          = pkg.ReadInt();
                info.Nimbus          = pkg.ReadInt();
                info.ConsortiaID     = pkg.ReadInt();
                info.ConsortiaName   = pkg.ReadString();
                info.ConsortiaLevel  = pkg.ReadInt();
                info.ConsortiaRepute = pkg.ReadInt();
                info.Win             = pkg.ReadInt();
                info.Total           = pkg.ReadInt();
                info.Attack          = pkg.ReadInt();
                info.Defence         = pkg.ReadInt();
                info.Agility         = pkg.ReadInt();
                info.Luck            = pkg.ReadInt();
                info.FightPower      = pkg.ReadInt();
                info.IsMarried       = pkg.ReadBoolean();
                if (info.IsMarried)
                {
                    info.SpouseID   = pkg.ReadInt();
                    info.SpouseName = pkg.ReadString();
                }
                totalFightPower                      += info.FightPower;
                proxyPlayerInfo.BaseAttack            = pkg.ReadDouble();
                proxyPlayerInfo.BaseDefence           = pkg.ReadDouble();
                proxyPlayerInfo.BaseAgility           = pkg.ReadDouble();
                proxyPlayerInfo.BaseBlood             = pkg.ReadDouble();
                proxyPlayerInfo.TemplateId            = pkg.ReadInt();
                proxyPlayerInfo.CanUserProp           = pkg.ReadBoolean();
                proxyPlayerInfo.SecondWeapon          = pkg.ReadInt();
                proxyPlayerInfo.StrengthLevel         = pkg.ReadInt();
                proxyPlayerInfo.GPAddPlus             = pkg.ReadDouble();
                proxyPlayerInfo.GMExperienceRate      = pkg.ReadFloat();
                proxyPlayerInfo.AuncherExperienceRate = pkg.ReadFloat();
                proxyPlayerInfo.OfferAddPlus          = pkg.ReadDouble();
                proxyPlayerInfo.GMOfferRate           = pkg.ReadFloat();
                proxyPlayerInfo.AuncherOfferRate      = pkg.ReadFloat();
                proxyPlayerInfo.GMRichesRate          = pkg.ReadFloat();
                proxyPlayerInfo.AuncherRichesRate     = pkg.ReadFloat();
                proxyPlayerInfo.AntiAddictionRate     = pkg.ReadDouble();
                List <BufferInfo> infos = new List <BufferInfo>();
                int buffercout          = pkg.ReadInt();
                for (int j = 0; j < buffercout; j++)
                {
                    BufferInfo buffinfo = new BufferInfo();
                    buffinfo.Type      = pkg.ReadInt();
                    buffinfo.IsExist   = pkg.ReadBoolean();
                    buffinfo.BeginDate = pkg.ReadDateTime();
                    buffinfo.ValidDate = pkg.ReadInt();
                    buffinfo.Value     = pkg.ReadInt();
                    if (info != null)
                    {
                        infos.Add(buffinfo);
                    }
                }
                players[i]            = new ProxyPlayer(this, info, proxyPlayerInfo, infos);
                players[i].CanUseProp = proxyPlayerInfo.CanUserProp;
                int ec = pkg.ReadInt();
                for (int j = 0; j < ec; j++)
                {
                    players[i].EquipEffect.Add(pkg.ReadInt());
                }
                totalLevel += info.Grade;
            }
            if (players.Length != 0)
            {
                ProxyRoom room = new ProxyRoom(ProxyRoomMgr.NextRoomId(), roomId, players, this, totalLevel, totalFightPower, IsArea);
                room.GuildId  = guildId;
                room.AreaID   = areaId;
                room.GameType = (eGameType)gameType;
                ProxyRoom oldroom = null;
                Dictionary <int, ProxyRoom> rooms;
                Monitor.Enter(rooms = this.m_rooms);
                try
                {
                    if (this.m_rooms.ContainsKey(roomId))
                    {
                        oldroom = this.m_rooms[roomId];
                        this.m_rooms.Remove(roomId);
                    }
                }
                finally
                {
                    Monitor.Exit(rooms);
                }
                if (oldroom != null)
                {
                    ProxyRoomMgr.RemoveRoom(oldroom);
                }
                Monitor.Enter(rooms = this.m_rooms);
                try
                {
                    if (!this.m_rooms.ContainsKey(roomId))
                    {
                        this.m_rooms.Add(roomId, room);
                        this.SendFightRoomID(roomId, room.RoomId);
                    }
                    else
                    {
                        room = null;
                    }
                }
                finally
                {
                    Monitor.Exit(rooms);
                }
                if (room != null)
                {
                    ProxyRoomMgr.AddRoom(room);
                }
                else
                {
                    ServerClient.log.ErrorFormat("Room already exists:{0}", roomId);
                }
            }
        }
Example #14
0
        public override bool Start()
        {
            bool result;

            IsRunning = 0;
            try
            {
                this.m_running = true;
                Thread.CurrentThread.Priority = ThreadPriority.Normal;
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.CurrentDomain_UnhandledException);



                if (!this.InitSocket(IPAddress.Parse(this.m_config.FightIP), this.m_config.FightPort))
                {
                    result = false;
                    FightServer.log.Error("初始化监听端口失败,请检查!");
                    return(result);
                }
                FightServer.log.Info("初始化监听端口成功!");



                if (!base.Start())
                {
                    result = false;
                    FightServer.log.Error("基础服务启动失败,请检查!");
                    return(result);
                }
                FightServer.log.Info("基础服务启动成功!");


                if (!ProxyRoomMgr.Setup())
                {
                    result = false;
                    FightServer.log.Error("启动房间管理服务失败,请检查!");
                    return(result);
                }
                ProxyRoomMgr.Start();
                FightServer.log.Info("启动房间管理服务成功!");

                if (!GameMgr.Setup(0, 4))
                {
                    result = false;
                    FightServer.log.Error("启动游戏管理服务失败,请检查!");
                    return(result);
                }
                GameMgr.Start();
                StartScriptComponents();
                GameEventMgr.Notify(ScriptEvent.Loaded);
                FightServer.log.Info("启动游戏管理服务成功!");
                GC.Collect(GC.MaxGeneration);
                FightServer.log.Warn("战斗服务器已启动!");
                result    = true;
                IsRunning = 1;
            }

            catch (Exception e)
            {
                FightServer.log.Error("Failed to start the server", e);
                result = false;
            }

            return(result);
        }
Example #15
0
        public void HandleGameRoomCreate(GSPacketIn pkg)
        {
            int roomId   = pkg.ReadInt();
            int gameType = pkg.ReadInt();
            int guildId  = pkg.ReadInt();

            int count      = pkg.ReadInt();
            int totalLevel = 0;

            IGamePlayer[] players = new IGamePlayer[count];
            for (int i = 0; i < count; i++)
            {
                PlayerInfo info = new PlayerInfo();
                info.ID              = pkg.ReadInt();
                info.NickName        = pkg.ReadString();
                info.Sex             = pkg.ReadBoolean();
                info.Hide            = pkg.ReadInt();
                info.Style           = pkg.ReadString();
                info.Colors          = pkg.ReadString();
                info.Skin            = pkg.ReadString();
                info.Offer           = pkg.ReadInt();
                info.GP              = pkg.ReadInt();
                info.Grade           = pkg.ReadInt();
                info.Repute          = pkg.ReadInt();
                info.ConsortiaID     = pkg.ReadInt();
                info.ConsortiaName   = pkg.ReadString();
                info.ConsortiaLevel  = pkg.ReadInt();
                info.ConsortiaRepute = pkg.ReadInt();

                info.Attack  = pkg.ReadInt();
                info.Defence = pkg.ReadInt();
                info.Agility = pkg.ReadInt();
                info.Luck    = pkg.ReadInt();

                double baseAttack    = pkg.ReadDouble();
                double baseDefence   = pkg.ReadDouble();
                double baseAgility   = pkg.ReadDouble();
                double baseBlood     = pkg.ReadDouble();
                int    templateId    = pkg.ReadInt();
                bool   canUserProp   = pkg.ReadBoolean();
                int    secondWeapon  = pkg.ReadInt();
                int    strengthLevel = pkg.ReadInt();


                double gprate    = pkg.ReadDouble();
                double offerrate = pkg.ReadDouble();
                double rate      = pkg.ReadDouble();
                int    serverid  = pkg.ReadInt();

                ItemTemplateInfo itemTemplate = ItemMgr.FindItemTemplate(templateId);
                ItemInfo         item         = null;
                if (secondWeapon != 0)
                {
                    ItemTemplateInfo secondWeaponTemp = ItemMgr.FindItemTemplate(secondWeapon);
                    item = ItemInfo.CreateFromTemplate(secondWeaponTemp, 1, 1);
                    item.StrengthenLevel = strengthLevel;
                }

                List <BufferInfo> infos = new List <BufferInfo>();

                int buffercout = pkg.ReadInt();
                for (int j = 0; j < buffercout; j++)
                {
                    BufferInfo buffinfo = new BufferInfo();
                    buffinfo.Type      = pkg.ReadInt();
                    buffinfo.IsExist   = pkg.ReadBoolean();
                    buffinfo.BeginDate = pkg.ReadDateTime();
                    buffinfo.ValidDate = pkg.ReadInt();
                    buffinfo.Value     = pkg.ReadInt();
                    if (info != null)
                    {
                        infos.Add(buffinfo);
                    }
                }

                players[i]            = new ProxyPlayer(this, info, itemTemplate, item, baseAttack, baseDefence, baseAgility, baseBlood, gprate, offerrate, rate, infos, serverid);
                players[i].CanUseProp = canUserProp;

                int ec = pkg.ReadInt();
                for (int j = 0; j < ec; j++)
                {
                    players[i].EquipEffect.Add(pkg.ReadInt());
                }
                totalLevel += info.Grade;
            }

            ProxyRoom room = new ProxyRoom(ProxyRoomMgr.NextRoomId(), roomId, players, this);

            room.GuildId  = guildId;
            room.GameType = (eGameType)gameType;

            lock (m_rooms)
            {
                if (!m_rooms.ContainsKey(roomId))
                {
                    m_rooms.Add(roomId, room);
                }
                else
                {
                    room = null;
                }
            }

            if (room != null)
            {
                ProxyRoomMgr.AddRoom(room);
            }
            else
            {
                log.ErrorFormat("Room already exists:{0}", roomId);
            }
        }
Example #16
0
        public void HandleGameRoomCancel(GSPacketIn pkg)
        {
            int roomId = pkg.Parameter1;

            ProxyRoomMgr.CancelRoom(roomId);
        }
Example #17
0
        public void OnAction(System.Collections.Hashtable parameters)
        {
            System.Console.WriteLine("This server GunnyII, edit and build by MrPhuong!");
            System.Console.WriteLine("Starting FightingServer ... please wait a moment!");
            FightServerConfig fightServerConfig = new FightServerConfig();

            try
            {
                fightServerConfig.Load();
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                System.Console.ReadKey();
                return;
            }
            FightServer.CreateInstance(fightServerConfig);
            FightServer.Instance.Start();
            bool flag = true;

            while (flag)
            {
                try
                {
                    System.Console.Write("> ");
                    string   text  = System.Console.ReadLine();
                    string[] array = text.Split(new char[]
                    {
                        ' '
                    });
                    string a;
                    if ((a = array[0].ToLower()) != null)
                    {
                        if (!(a == "clear"))
                        {
                            if (!(a == "list"))
                            {
                                if (a == "exit")
                                {
                                    flag = false;
                                }
                            }
                            else
                            {
                                if (array.Length > 1)
                                {
                                    string a2;
                                    if ((a2 = array[1]) != null)
                                    {
                                        if (!(a2 == "-client"))
                                        {
                                            if (!(a2 == "-room"))
                                            {
                                                if (a2 == "-game")
                                                {
                                                    System.Console.WriteLine("game list:");
                                                    System.Console.WriteLine("-------------------------------");
                                                    System.Collections.Generic.List <BaseGame> games = GameMgr.GetGames();
                                                    foreach (BaseGame current in games)
                                                    {
                                                        System.Console.WriteLine(current.ToString());
                                                    }
                                                    System.Console.WriteLine("-------------------------------");
                                                }
                                            }
                                            else
                                            {
                                                System.Console.WriteLine("room list:");
                                                System.Console.WriteLine("-------------------------------");
                                                ProxyRoom[] allRoom = ProxyRoomMgr.GetAllRoom();
                                                ProxyRoom[] array2  = allRoom;
                                                for (int i = 0; i < array2.Length; i++)
                                                {
                                                    ProxyRoom proxyRoom = array2[i];
                                                    System.Console.WriteLine(proxyRoom.ToString());
                                                }
                                                System.Console.WriteLine("-------------------------------");
                                            }
                                        }
                                        else
                                        {
                                            System.Console.WriteLine("server client list:");
                                            System.Console.WriteLine("--------------------");
                                            ServerClient[] allClients = FightServer.Instance.GetAllClients();
                                            ServerClient[] array3     = allClients;
                                            for (int j = 0; j < array3.Length; j++)
                                            {
                                                ServerClient serverClient = array3[j];
                                                System.Console.WriteLine(serverClient.ToString());
                                            }
                                            System.Console.WriteLine("-------------------");
                                        }
                                    }
                                }
                                else
                                {
                                    System.Console.WriteLine("list [-client][-room][-game]");
                                    System.Console.WriteLine("     -client:列出所有服务器对象");
                                    System.Console.WriteLine("     -room:列出所有房间对象");
                                    System.Console.WriteLine("     -game:列出所有游戏对象");
                                }
                            }
                        }
                        else
                        {
                            System.Console.Clear();
                        }
                    }
                }
                catch (System.Exception ex2)
                {
                    System.Console.WriteLine("Error:" + ex2.ToString());
                }
            }
            if (FightServer.Instance != null)
            {
                FightServer.Instance.Stop();
            }
        }
Example #18
0
        public void HandleGameRoomCreate(GSPacketIn pkg)
        {
            int num      = pkg.ReadInt();
            int gameType = pkg.ReadInt();
            int guildId  = pkg.ReadInt();
            int num2     = pkg.ReadInt();
            int num3     = 0;

            IGamePlayer[] array = new IGamePlayer[num2];
            for (int i = 0; i < num2; i++)
            {
                PlayerInfo playerInfo = new PlayerInfo();
                playerInfo.ID                    = pkg.ReadInt();
                playerInfo.NickName              = pkg.ReadString();
                playerInfo.Sex                   = pkg.ReadBoolean();
                playerInfo.typeVIP               = pkg.ReadByte();
                playerInfo.VIPLevel              = pkg.ReadInt();
                playerInfo.Hide                  = pkg.ReadInt();
                playerInfo.Style                 = pkg.ReadString();
                playerInfo.Colors                = pkg.ReadString();
                playerInfo.Skin                  = pkg.ReadString();
                playerInfo.Offer                 = pkg.ReadInt();
                playerInfo.GP                    = pkg.ReadInt();
                playerInfo.Grade                 = pkg.ReadInt();
                playerInfo.Repute                = pkg.ReadInt();
                playerInfo.ConsortiaID           = pkg.ReadInt();
                playerInfo.ConsortiaName         = pkg.ReadString();
                playerInfo.ConsortiaLevel        = pkg.ReadInt();
                playerInfo.ConsortiaRepute       = pkg.ReadInt();
                playerInfo.badgeID               = pkg.ReadInt();
                playerInfo.weaklessGuildProgress = Base64.decodeToByteArray(pkg.ReadString());
                playerInfo.Attack                = pkg.ReadInt();
                playerInfo.Defence               = pkg.ReadInt();
                playerInfo.Agility               = pkg.ReadInt();
                playerInfo.Luck                  = pkg.ReadInt();
                playerInfo.hp                    = pkg.ReadInt();
                playerInfo.FightPower            = pkg.ReadInt();
                playerInfo.IsMarried             = pkg.ReadBoolean();
                if (playerInfo.IsMarried)
                {
                    playerInfo.SpouseID   = pkg.ReadInt();
                    playerInfo.SpouseName = pkg.ReadString();
                }
                ProxyPlayerInfo proxyPlayerInfo = new ProxyPlayerInfo();
                proxyPlayerInfo.BaseAttack        = pkg.ReadDouble();
                proxyPlayerInfo.BaseDefence       = pkg.ReadDouble();
                proxyPlayerInfo.BaseAgility       = pkg.ReadDouble();
                proxyPlayerInfo.BaseBlood         = pkg.ReadDouble();
                proxyPlayerInfo.TemplateId        = pkg.ReadInt();
                proxyPlayerInfo.CanUserProp       = pkg.ReadBoolean();
                proxyPlayerInfo.SecondWeapon      = pkg.ReadInt();
                proxyPlayerInfo.StrengthLevel     = pkg.ReadInt();
                proxyPlayerInfo.GPAddPlus         = pkg.ReadDouble();
                proxyPlayerInfo.OfferAddPlus      = pkg.ReadDouble();
                proxyPlayerInfo.AntiAddictionRate = pkg.ReadDouble();
                proxyPlayerInfo.ServerId          = pkg.ReadInt();
                UsersPetinfo usersPetinfo = new UsersPetinfo();
                int          num4         = pkg.ReadInt();
                if (num4 == 1)
                {
                    usersPetinfo.Place      = pkg.ReadInt();
                    usersPetinfo.TemplateID = pkg.ReadInt();
                    usersPetinfo.ID         = pkg.ReadInt();
                    usersPetinfo.Name       = pkg.ReadString();
                    usersPetinfo.UserID     = pkg.ReadInt();
                    usersPetinfo.Level      = pkg.ReadInt();
                    usersPetinfo.Skill      = pkg.ReadString();
                    usersPetinfo.SkillEquip = pkg.ReadString();
                }
                else
                {
                    usersPetinfo = null;
                }
                List <BufferInfo> list = new List <BufferInfo>();
                int num5 = pkg.ReadInt();
                for (int j = 0; j < num5; j++)
                {
                    BufferInfo bufferInfo = new BufferInfo();
                    bufferInfo.Type       = pkg.ReadInt();
                    bufferInfo.IsExist    = pkg.ReadBoolean();
                    bufferInfo.BeginDate  = pkg.ReadDateTime();
                    bufferInfo.ValidDate  = pkg.ReadInt();
                    bufferInfo.Value      = pkg.ReadInt();
                    bufferInfo.ValidCount = pkg.ReadInt();
                    if (playerInfo != null)
                    {
                        list.Add(bufferInfo);
                    }
                }
                List <ItemInfo> list2 = new List <ItemInfo>();
                int             num6  = pkg.ReadInt();
                for (int k = 0; k < num6; k++)
                {
                    int      templateId = pkg.ReadInt();
                    int      hole       = pkg.ReadInt();
                    ItemInfo itemInfo   = ItemInfo.CreateFromTemplate(ItemMgr.FindItemTemplate(templateId), 1, 1);
                    itemInfo.Hole1 = hole;
                    list2.Add(itemInfo);
                }
                array[i]            = new ProxyPlayer(this, playerInfo, proxyPlayerInfo, usersPetinfo, list, list2);
                array[i].CanUseProp = proxyPlayerInfo.CanUserProp;
                num3 += playerInfo.Grade;
            }
            ProxyRoom proxyRoom = new ProxyRoom(ProxyRoomMgr.NextRoomId(), num, array, this);

            proxyRoom.GuildId  = guildId;
            proxyRoom.GameType = (eGameType)gameType;
            Dictionary <int, ProxyRoom> rooms;

            Monitor.Enter(rooms = this.m_rooms);
            try
            {
                if (!this.m_rooms.ContainsKey(num))
                {
                    this.m_rooms.Add(num, proxyRoom);
                }
                else
                {
                    proxyRoom = null;
                }
            }
            finally
            {
                Monitor.Exit(rooms);
            }
            if (proxyRoom != null)
            {
                ProxyRoomMgr.AddRoom(proxyRoom);
                return;
            }
            ServerClient.log.ErrorFormat("Room already exists:{0}", num);
        }
Example #19
0
        public override bool Start()
        {
            bool result;

            try
            {
                LogProvider.Default = new LogProvider(new LogConfig {
                    FilePath = "./log/fight/", UseConsole = true, UseFile = true
                });
                this.m_running = true;
                Thread.CurrentThread.Priority = ThreadPriority.Normal;
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.CurrentDomain_UnhandledException);

                CrossFightServer.log.Warn("正在初始化…………");
                if (!Sql_DbObject.TryConnection())
                {
                    result = false;
                    CrossFightServer.log.Error("数据库连接失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("数据库连接成功!");

                if (!this.InitSocket(IPAddress.Parse(this.m_config.IP), this.m_config.Port))
                {
                    result = false;
                    CrossFightServer.log.Error("初始化监听端口失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化监听端口成功!");



                if (!MapMgr.Init())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化地图失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化地图成功!");

                if (!ItemMgr.Init())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化物品失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化物品成功!");

                if (!PropItemMgr.Init())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化道具失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化道具成功!");

                if (!BallMgr.Init())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化炸弹失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化炸弹成功!");

                if (!DropMgr.Init())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化掉落失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化掉落成功!");

                if (!NPCInfoMgr.Init())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化npc失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化npc成功!");

                if (!LanguageMgr.Load())
                {
                    result = false;
                    CrossFightServer.log.Error("初始化语言包失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("初始化语言包成功!");



                if (!base.Start())
                {
                    result = false;
                    CrossFightServer.log.Error("基础服务启动失败,请检查!");
                    return(result);
                }
                CrossFightServer.log.Info("基础服务启动成功!");


                if (!ProxyRoomMgr.Setup())
                {
                    result = false;
                    CrossFightServer.log.Error("启动房间管理服务失败,请检查!");
                    return(result);
                }
                ProxyRoomMgr.Start();
                CrossFightServer.log.Info("启动房间管理服务成功!");

                if (!GameMgr.Setup(0, 4))
                {
                    result = false;
                    CrossFightServer.log.Error("启动游戏管理服务失败,请检查!");
                    return(result);
                }
                GameMgr.Start();
                StartScriptComponents();
                GameEventMgr.Notify(ScriptEvent.Loaded);
                CrossFightServer.log.Info("启动游戏管理服务成功!");
                GC.Collect(GC.MaxGeneration);
                CrossFightServer.log.Warn("战斗服务器已启动!");
                result = true;
            }

            catch (Exception e)
            {
                CrossFightServer.log.Error("Failed to start the server", e);
                result = false;
            }

            return(result);
        }
Example #20
0
        public override bool Start()
        {
            if (this.m_running)
            {
                return(false);
            }
            bool result;

            try
            {
                this.m_running = true;
                Thread.CurrentThread.Priority = ThreadPriority.Normal;
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.CurrentDomain_UnhandledException);
                if (!this.InitComponent(this.InitSocket(this.m_config.Ip, this.m_config.Port), "InitSocket Port:" + this.m_config.Port))
                {
                    result = false;
                }
                else
                {
                    if (!this.InitComponent(this.StartScriptComponents(), "Script components"))
                    {
                        result = false;
                    }
                    else
                    {
                        if (!this.InitComponent(ProxyRoomMgr.Setup(), "RoomMgr.Setup"))
                        {
                            result = false;
                        }
                        else
                        {
                            if (!this.InitComponent(GameMgr.Setup(0, 4), "GameMgr.Setup"))
                            {
                                result = false;
                            }
                            else
                            {
                                if (!this.InitComponent(MapMgr.Init(), "MapMgr Init"))
                                {
                                    result = false;
                                }
                                else
                                {
                                    if (!this.InitComponent(ItemMgr.Init(), "ItemMgr Init"))
                                    {
                                        result = false;
                                    }
                                    else
                                    {
                                        if (!this.InitComponent(PropItemMgr.Init(), "PropItemMgr Init"))
                                        {
                                            result = false;
                                        }
                                        else
                                        {
                                            if (!this.InitComponent(BallMgr.Init(), "BallMgr Init"))
                                            {
                                                result = false;
                                            }
                                            else
                                            {
                                                if (!this.InitComponent(BallConfigMgr.Init(), "BallConfigMgr Init"))
                                                {
                                                    result = false;
                                                }
                                                else
                                                {
                                                    if (!this.InitComponent(DropMgr.Init(), "DropMgr Init"))
                                                    {
                                                        result = false;
                                                    }
                                                    else
                                                    {
                                                        if (!this.InitComponent(NPCInfoMgr.Init(), "NPCInfoMgr Init"))
                                                        {
                                                            result = false;
                                                        }
                                                        else
                                                        {
                                                            if (!this.InitComponent(WindMgr.Init(), "WindMgr Init"))
                                                            {
                                                                result = false;
                                                            }
                                                            else
                                                            {
                                                                if (!this.InitComponent(GoldEquipMgr.Init(), "GoldEquipMgr Init"))
                                                                {
                                                                    result = false;
                                                                }
                                                                else
                                                                {
                                                                    if (!this.InitComponent(LanguageMgr.Setup(""), "LanguageMgr Init"))
                                                                    {
                                                                        result = false;
                                                                    }
                                                                    else
                                                                    {
                                                                        GameEventMgr.Notify(ScriptEvent.Loaded);
                                                                        if (!this.InitComponent(base.Start(), "base.Start()"))
                                                                        {
                                                                            result = false;
                                                                        }
                                                                        else
                                                                        {
                                                                            ProxyRoomMgr.Start();
                                                                            GameMgr.Start();
                                                                            GameEventMgr.Notify(GameServerEvent.Started, this);
                                                                            GC.Collect(GC.MaxGeneration);
                                                                            FightServer.log.Info("GameServer is now open for connections!");
                                                                            result = true;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                FightServer.log.Error("Failed to start the server", exception);
                result = false;
            }
            return(result);
        }