Example #1
0
 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);
             }
         }
     }
 }
Example #2
0
        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);
        }
Example #3
0
 private void ServerMsgTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (MsgSystem.Msgs == null || MsgSystem.Msgs.Count <= 1)
     {
         return;
     }
     ThreadPool.QueueUserWorkItem(new WaitCallback(
                                      delegate(object o)
     {
         Say(GameManager.getMessage(MsgSystem.getNextMessage(), PlayerType.Yellow));
     }
                                      ));
 }