public bool Start() { if (IsListening) { return(false); } try { string script = Tool.Combine(Config.Path, "script"); string cdb = Tool.Combine(Config.Path, "cards.cdb"); string windb = Tool.Combine(Config.Path, "win.db"); string lflist = Tool.Combine(Config.Path, "lflist.conf"); string namelist = Tool.Combine(Program.Config.Path, "namelist.txt"); string msgfile = Tool.Combine(Program.Config.Path, "server_msg.txt"); // Logger.Debug("script:"+script); // Logger.Debug("windb:"+windb); // Logger.Debug("lflist:"+lflist); Api.Init(Config.Path, script, cdb); BanlistManager.Init(lflist); WinInfo.Init(windb); RoomManager.init(namelist); Messages.Init(msgfile); if (Config.ApiPort > 0) { Logger.Info("Connecting api server."); if (!ServerApi.Init(Config.ApiPort)) { Logger.Warn("connect api server fail."); } else { Logger.Info("Connect api server ok"); } } m_listener = new AsyncTcpListener <GameSession>(IPAddress.Any, Config.ServerPort, banmode: Config.isBanIP); m_listener.OnConnect += new AsyncTcpListener <GameSession> .ConnectEventHandler(Listener_OnConnect); m_listener.OnReceive += new AsyncTcpListener <GameSession> .ReceiveEventHandler(Listener_OnReceive); m_listener.OnDisconnect += new AsyncTcpListener <GameSession> .DisconnectEventHandler(Listener_OnDisconnect); m_listener.OnCheckClient += new AsyncTcpListener <GameSession> .CheckEventHandler(Listener_OnCheckClient); m_listener.Start(); ServerApi.OnServerInfo(this); IsListening = true; } catch (SocketException) { Logger.Warn("The " + Config.ServerPort + " port is currently in use."); return(false); } catch (Exception e) { Logger.Error(e); return(false); } Logger.Info("Listening on port " + Config.ServerPort); return(true); }
public void Reload() { Program.Config.Load(); Api.Init(Program.Config.Path, Program.Config.ScriptFolder, Program.Config.CardCDB); BanlistManager.Init(Program.Config.BanlistFile); MsgSystem.Init(Program.Config.File_ServerMsgs); WinInfo.Init(Program.Config.WinDbName); banNames.Clear(); if (File.Exists(Program.Config.File_BanAccont)) { string[] lines = File.ReadAllLines(Program.Config.File_BanAccont); foreach (string line in lines) { if (string.IsNullOrEmpty(line) || line.StartsWith("#")) { continue; } string name = line.Trim(); if (!banNames.Contains(name)) { banNames.Add(name); } } } }
public bool Start(int port = 0) { try { Api.Init(Program.Config.Path, Program.Config.ScriptFolder, Program.Config.CardCDB); BanlistManager.Init(Program.Config.BanlistFile); //DecksManager.Init(); MsgSystem.Init(Program.Config.File_ServerMsgs); WinInfo.Init(Program.Config.WinDbName); if (File.Exists(Program.Config.File_BanAccont)) { string[] lines = File.ReadAllLines(Program.Config.File_BanAccont); foreach (string line in lines) { if (string.IsNullOrEmpty(line) || line.StartsWith("#")) { continue; } string name = line.Trim(); if (!banNames.Contains(name)) { banNames.Add(name); } } } try{ Directory.CreateDirectory(Program.Config.replayFolder); }catch (IOException) { } IsListening = true; m_listener = new TcpListener(IPAddress.Any, port == 0 ? Program.Config.ServerPort : port); m_listener.Start(); Thread acceptThread = new Thread(new ThreadStart(AcceptClient)); acceptThread.IsBackground = true; acceptThread.Start(); WinSaveTimer.Start(); ApiServer.Start(); } catch (SocketException) { Logger.WriteError("The " + (port == 0 ? Program.Config.ServerPort : port) + " port is currently in use."); return(false); } catch (Exception e) { Logger.WriteError(e); return(false); } Logger.WriteLine("Listening on port " + (port == 0 ? Program.Config.ServerPort : port)); if (BanlistManager.Banlists != null && BanlistManager.Banlists.Count > 0) { Logger.WriteLine("Banlist = " + BanlistManager.Banlists[0].Name); } return(true); }
public bool Start(int port = 0) { try { Api.Init(Program.Config.Path, Program.Config.ScriptFolder, Program.Config.CardCDB); BanlistManager.Init(Program.Config.BanlistFile); m_listener = new TcpListener(IPAddress.Any, port == 0 ? Program.Config.ServerPort : port); m_listener.Start(); IsListening = true; } catch (SocketException) { Logger.WriteError("The " + (port == 0 ? Program.Config.ServerPort : port) + " port is currently in use."); return(false); } catch (Exception e) { Logger.WriteError(e); return(false); } Logger.WriteLine("Listening on port " + (port == 0 ? Program.Config.ServerPort : port)); return(true); }