/// <summary> /// Loads all necessary components and starts the server. /// </summary> public void Run() { if (_running) { throw new Exception("Server is already running."); } int x, y, width, height; GetWindowPosition(out x, out y, out width, out height); SetWindowPosition(width + 5, 0, width, height); ConsoleUtil.WriteHeader("Game Server", ConsoleColor.DarkGreen); ConsoleUtil.LoadingTitle(); NavigateToRoot(); // Conf LoadConf(Config = new GameConf()); // Database InitDatabase(Database = new GameDatabase(), Config); // Start Server = new DefaultServer(Config.Game.Port); Server.Start(); ConsoleUtil.RunningTitle(); _running = true; // Commands var commands = new GameConsoleCommands(); commands.Wait(); }
public static void Start(GameConf gameConf) { if (s_hasSent) { return; } s_gameConf = gameConf; s_sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //255.255.255.255 s_ieps = new IPEndPoint[BroadConstant.BroadcastPorts.Length]; for (int i = 0; i < s_ieps.Length; i++) { s_ieps[i] = new IPEndPoint(IPAddress.Broadcast, BroadConstant.BroadcastPorts[i]); } s_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); s_sendThread = new Thread(BroadcastMessage); s_sendThread.Start(); s_hasSent = true; //sock.Close(); }
/// <summary> /// 广播房间信息以连接 /// </summary> /// <param name="proto"></param> static void RecieveRoomConf(object proto) { RoomBroadCast roomData = proto as RoomBroadCast; GameConf conf = new GameConf(); conf.Name = roomData.roomConf.name; conf.MemCount = roomData.roomConf.maxMemCount; conf.MapType = (MapType)roomData.roomConf.mapType; conf.ForceKill = roomData.roomConf.forceKill; Globals.Instance.SendMessage(MsgType.OnFindServer, roomData.address, roomData.port, conf); }
/// <summary> /// 广播房间信息以连接 /// </summary> /// <param name="address"></param> /// <param name="port"></param> /// <param name="gameConf"></param> public static byte[] SendRoomConf(string address, int port, GameConf gameConf) { RoomBroadCast roomBroadCast = new RoomBroadCast(); roomBroadCast.address = address; roomBroadCast.port = port; RoomConf conf = new RoomConf(); conf.name = gameConf.Name; conf.maxMemCount = gameConf.MemCount; conf.mapType = (int)gameConf.MapType; conf.forceKill = gameConf.ForceKill; roomBroadCast.roomConf = conf; return(Serialize(Cmd.BroadcastRoomConf, roomBroadCast)); }
public static void LoginResponse(Player player, int ownerGuid, List <Player> players, GameConf conf) { LoginResponse response = new LoginResponse(); response.guid = player.GUID; foreach (Player p in players) { Member m = new Member(); m.guid = p.GUID; m.name = p.Name; response.members.Add(m); } RoomConf roomConf = new RoomConf(); roomConf.name = conf.Name; roomConf.mapType = (int)conf.MapType; roomConf.maxMemCount = conf.MemCount; roomConf.forceKill = conf.ForceKill; response.roomConf = roomConf; response.ownerGuid = ownerGuid; SerializeAndSend(player, Cmd.LoginResponse, response); }
public void Run() { if (_running) { throw new Exception("Server is already running."); } var watch = System.Diagnostics.Stopwatch.StartNew(); ConsoleHelper.WriteHeader("Test", ConsoleColor.Green); Annoucement = new Dictionary <int, Annoucement>(); Log.Info("Server startup requested"); Log.Info($"Server Version {Util.Version.GetVersion()}"); NavigateToRootFolder(); LoadConf(Config = new GameConf()); LoadErrorMessages(); InitDatabase(Database = new GameDatabase(), Config); ServerMain.Instance.LoadAnnoucement(); /* * if(Config.Game.MockData) * { * AccountTable = new MockAccount(); * CharacterTable = new MockCharacter(); * Log.Info("Loaded Mock Data"); * } * else * { * * AccountTable = new Accounts(); * CharacterTable = new Characters(); * * } */ if (Config.Game.LoadPacketDatabase) { if (GameServer.PacketNameDatabase == null) { GameServer.PacketNameDatabase = new Dictionary <ushort, string>(); if (File.Exists("system/conf/packets.txt")) { var src = File.ReadAllText("system/conf/packets.txt"); foreach (var line in src.Split('\n')) { if (line.Length <= 3) { continue; } var lineSplit = line.Split(':'); var id = ushort.Parse(lineSplit[0]); GameServer.PacketNameDatabase[id] = lineSplit[1].Trim().Split('_')[1]; } } } } //AccountTable.Load(Database.Connection); //CharacterTable.Load(Database.Connection); // QuizTable = new Quizzes(); // QuizTable.Load(Database.Connection); Server = new GameServer(Config.Ip.ServerIp, Config.Ip.ServerPort, Config.Game.Encryption, Config.Game.IsTeacherComponentEnabled); Server.Start(); ApiServer = ApiServer.Create(Config.Ip); ApiServer.Toggle(); ConsoleHelper.RunningTitle(); _running = true; watch.Stop(); Log.Info("Ready after {0}ms", watch.ElapsedMilliseconds); // Start logging Log.Archive = "archive"; Log.LogFile = "server.log"; // LogoutTimerScript = new Timer(ExecuteLogout, null, 0, 60000); //var x = new ConsoleCommands(); //x.Wait(); }
/// <summary> /// Loads all necessary components and starts the server. /// </summary> public void Run() { if (_running) { throw new Exception("Server is already running."); } var watch = System.Diagnostics.Stopwatch.StartNew(); int x, y, width, height; Win32.GetWindowPosition(out x, out y, out width, out height); Win32.SetWindowPosition(width + 5, 0, width, height); ConsoleUtil.WriteHeader($"Game Server ({Shared.Util.Version.GetVersion()})", ConsoleColor.DarkGreen); ConsoleUtil.LoadingTitle(); Log.Info("Server startup requested"); Log.Info($"Server Version {Shared.Util.Version.GetVersion()}"); NavigateToRoot(); // Conf LoadConf(Config = new GameConf()); // Database InitDatabase(Database = new GameDatabase(), Config); // Data /*var reader = new TdfReader(); * if (reader.Load("system/data/QuestServer.tdf")) * { * Log.Debug("Loading Quest Table"); * QuestTable = XiStrQuest.LoadFromTdf(reader); * if(QuestTable.Count == 0) throw new InvalidDataException("QuestTable corrupt!"); * Log.Debug("Quest Table Initialized with {0:D} rows.", QuestTable.Count); * } * else * { * Log.Debug("Quest Table Load failed."); * }*/ Log.Info("Loading Vehicles.."); if (File.Exists("system/data/Vehicles.xml")) { try { Vehicles = GameData.LoadVehicleData("system/data/vehicles.xml"); } catch (Exception) { #if !DEBUG throw new Exception("Vehicle Data corrupt"); #else throw; #endif } } Log.Info("Loading VShop Items.."); if (File.Exists("system/data/VShopItems.xml")) { try { VisualItems = GameData.LoadVShopItems("system/data/VShopItems.xml"); } catch (Exception) { #if !DEBUG throw new Exception("VShop Items corrupt!"); #else throw; #endif } } else { throw new FileNotFoundException("VShopItem data not found!"); } Log.Info("VShop Items loaded with {0:D} entries", VisualItems.Count); Log.Info("Loading Quest Table"); if (File.Exists("system/data/Quests.xml")) { try { Quests = GameData.LoadQuests("system/data/Quests.xml"); } catch (Exception) { #if !DEBUG throw new Exception("Quest data corrupt!"); #else throw; #endif } } else { throw new FileNotFoundException("Quest data not found!"); } Log.Info("Quest Table loaded with {0:D} entries", Quests.Count); // ################# ITEMS ################ // Log.Info("Loading Item Table"); if (File.Exists("system/data/Items.xml")) { try { Items = GameData.LoadItems("system/data/Items.xml", "system/data/UseItems.xml"); } catch (Exception) { #if !DEBUG throw new Exception("Items data corrupt!"); #else throw; #endif } } else { throw new FileNotFoundException("Items data not found!"); } Log.Info("Item Table loaded with {0:D} entries", Items.Count); /*reader = new TdfReader(); * if (reader.Load("system/data/ItemClient.tdf")) * { * Log.Debug("Loading Item Table"); * ItemTable = XiStrItem.LoadFromTdf(reader); * if(ItemTable.Count == 0) throw new InvalidDataException("ItemTable corrupt!"); * Log.Debug("Item Table Initialized with {0:D} rows.", ItemTable.Count); * }*/ // TODO: Load VehicleList.csv to VehicleInfo //VehicleInfo.Load("system/data/VehicleList.csv"); var reader = new TdfReader(); if (reader.Load("system/data/LevelServer.tdf")) { Log.Debug("Loading Exp Table"); LevelTable = XiExpTable.LoadFromTdf(reader); if (LevelTable.Count == 0) { throw new InvalidDataException("LevelTable corrupt!"); } Log.Debug("Exp Table Initialized with {0:D} rows.", LevelTable.Count); } else { Log.Debug("Exp Table Load failed."); } // Start Server = new DefaultServer(Config.Game.Port); Server.Start(); ConsoleUtil.RunningTitle(); _running = true; watch.Stop(); Log.Info("Ready after {0}ms", watch.ElapsedMilliseconds); // Commands var commands = new GameConsoleCommands(); commands.Wait(); }