static async Task Main(string[] args) { //setup our DI var serviceProvider = new ServiceCollection() .AddSingleton <ClientService, ClientService>() .BuildServiceProvider(); int portNo = 0; string userName = ""; if (args.Length > 0) { Int32.TryParse(args[0], out portNo); userName = args[1]; if (portNo == 0 || string.IsNullOrEmpty(userName)) { Console.WriteLine("Invalid command! The format is: TestChat [portNo] [userName]!"); Console.ReadLine(); return; } ServerChat.StartChat(portNo); } else { Console.WriteLine("Invalid command! The format is: TestChat [portNo] [userName]!"); Console.ReadLine(); return; } var clientService = serviceProvider.GetService <ClientService>(); await StartChat(clientService, userName, portNo); }
public static void AssemblyInit(TestContext context) { // Initalization code goes here string port = "8181"; _chatService = new(ConnectionString, port, "helia", "cheerio"); _serverChat = new(_chatService); _serverChat.Connect(waitForInput: false); }
private void HandleLocalChat(WorldSession session, ClientChat chat) { var serverChat = new ServerChat { Guid = session.Player.Guid, Channel = chat.Channel, Name = session.Player.Name, Text = chat.Message, Formats = ParseChatLinks(session, chat).ToList(), }; session.Player.Map.Search( session.Player.Position, LocalChatDistace, new SearchCheckRangePlayerOnly(session.Player.Position, LocalChatDistace, session.Player), out List <GridEntity> intersectedEntities ); intersectedEntities.ForEach(e => ((Player)e).Session.EnqueueMessageEncrypted(serverChat)); SendChatAccept(session); }
/// <summary> /// Inits this instance. /// </summary> public static void Init() { Running = true; Logger.WriteLog("--------- Server Started at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " ---------"); Logger.Log("Debug mode started", LogType.Debug); //TODO Add debug messages //TODO load the level if it exists Block.InIt(); Logger.Log("Starting update timer", LogType.Debug); UpdateTimer = new System.Threading.Timer((e) => Update(), null, 0, 100); Logger.Log("Log timer started", LogType.Debug); Logger.Log("Loading DLL's", LogType.Debug); LoadAllDlls.Init(); Logger.Log("Finished loading DLL's", LogType.Debug); Logger.Log("Sending Heartbeat..", LogType.Debug); Logger.Log("Auto-Updater Starting..", LogType.Debug); Updater.InIt(); HeartThread = new Thread(new ThreadStart(Heartbeat.ActivateHeartBeat)); HeartThread.Start(); Logger.Log("Starting Physics Tick..", LogType.Debug); PhysicsBlock.InIt(); CmdReloadCmds reload = new CmdReloadCmds(); reload.Initialize(); Groups.PlayerGroup.Load(); VerifyGroup = Groups.PlayerGroup.Find(ServerSettings.GetSetting("VerifyGroup")); Mainlevel = Level.LoadLevel(ServerSettings.GetSetting("Main-Level")); if (Mainlevel == null) { Mainlevel = Level.CreateLevel(new Vector3S(256, 128, 64), Level.LevelTypes.Flat); ServerSettings.SetSetting("Main-Level", null, "main"); } Level.Levels.Add(Mainlevel); if (ServerSettings.GetSettingBoolean("LoadAllLevels")) { Level.LoadAllLevels(); } BlockQueue.Start(); Backup.StartBackup(); Database.Init(); CreateCoreFiles(); InternetUtils = new InetUtils(); InetUtils.InternetAvailable = InetUtils.CanConnectToInternet(); Logger.Log("Loading Bans", LogType.Debug); Logger.Log("IPBANS", LogType.Debug); IPBans = new List <string>(File.ReadAllLines("bans/IPBans.txt")); Logger.Log("IPBANS", LogType.Debug); UsernameBans = new List <string>(File.ReadAllLines("bans/NameBans.txt")); StartListening(); Started = true; if (OnServerFinishSetup != null) { OnServerFinishSetup(); } blockThread = new Thread(new ThreadStart(delegate { while (true) { Thread.Sleep(60000); Level.Levels.ForEach(delegate(Level l) { try { l.SaveToBinary(); } catch (Exception e) { Logger.LogError(e); } }); } })); blockThread.Start(); Logger.Log("[Important]: Server Started.", Color.Black, Color.White); if (!ServerSettings.GetSettingBoolean("VerifyNames")) { Logger.Log("[Important]: The server is running with verify names off! This could lead to bad things! Please turn on verify names if you dont know the risk and dont want these bad things to happen!", LogType.Critical); } if (ServerSettings.GetSettingBoolean("IRC-Enabled")) { try { IRC = new ServerChat(); IRC.Connect(); } catch (Exception e) { Logger.LogError(e); } } if (ServerSettings.GetSettingBoolean("GC-Enabled")) { GC = new GlobalChat(); try { GC.Connect(); } catch (Exception e) { Logger.LogError(e); } } try { RC = new ConsoleListener(); RC.Start(); } catch { } PlayerConnectionTimeoutChecker = new Thread(() => { int sleep = ServerSettings.GetSettingInt("AutoTimeout"); if (sleep < 0) { sleep = 30; } if (sleep != 0) { while (Running) { for (int i = 0; i < sleep && Running; i++) { Thread.Sleep(1000); } if (!Running) { break; } foreach (Player p in Players) { if (p.lastReceived.AddSeconds(sleep) < DateTime.Now) { #if !DEBUG p.Kick("The connection timed out"); #endif } } } } }); PlayerConnectionTimeoutChecker.Start(); }
//Send Message Send private void SendBtn_Click(object sender, EventArgs e) { server.SendMessageToAllUsers(ServerChat.Text); ServerChat.Clear(); }
private void Start() { serverchat = GetComponent <ServerChat>(); }
static void Main() { // Read in the config and initialise the logging module Config = Config.Load(CONFIG_FILE); Logger = new Logger(Config.LogPath, Config.DisplayVerbosity, Config.LogVerbosity); // Set up module instances Connections = new NetServer(new IPEndPoint(Config.Address, Config.Port), Config.MaxConnections); Authenticator = new ServerAuthenticator( netServer: Connections, serverName: Config.ServerName, serverDescription: Config.ServerDescription, authType: Config.AuthType ); UserManager = new ServerUserManager(Connections, Authenticator, Config.MaxDisplayNameLength); Chat = new ServerChat(Connections, Authenticator, UserManager, Config.ChatHistoryLength); Trading = new ServerTrading(Connections, Authenticator, UserManager); // Add handler for ILoggable modules Authenticator.OnLogEntry += ILoggableHandler; UserManager.OnLogEntry += ILoggableHandler; Chat.OnLogEntry += ILoggableHandler; Trading.OnLogEntry += ILoggableHandler; // Load saved data Authenticator.Load(Config.CredentialDatabasePath); UserManager.Load(Config.UserDatabasePath); Chat.Load(Config.ChatHistoryPath); Trading.Load(Config.TradeDatabasePath); // Start listening for connections Connections.Start(); // State our auth type and where we're listening from Logger.Log(Verbosity.INFO, string.Format("Accepting auth type \"{0}\"", Config.AuthType.ToString())); Logger.Log(Verbosity.INFO, string.Format("Phinix server version {0} listening on {1}:{2}", Version, Connections.Endpoint.Address, Connections.Endpoint.Port)); // Set up an exit condition on SIGINT/Ctrl+C Console.CancelKeyPress += shutdownHandler; // Start interpreting commands CommandInterpreter interpreter = new CommandInterpreter(); while (!exiting) { // Wait until we've got a command to interpret string line = Console.ReadLine(); // Don't do anything if the command is empty if (string.IsNullOrEmpty(line)) { continue; } // Break the line down into the command and its arguments List <string> arguments = new List <string>(line.Split(' ')); string command = arguments.First(); arguments.RemoveAt(0); // Remove the command from the argument list // Check if we've been given the exit command // This is checked here to avoid weird workarounds from the interpreter if (command == "exit" || command == "quit" || command == "stop") { shutdownHandler(); break; } // Interpret the command and its arguments interpreter.Run(command, arguments); } }