public MinecraftServer(MinecraftRunner runner, ServerHub hub, string serverFolder, Settings settings) { Runner = runner; Hub = hub; MinecraftServerFolder = serverFolder; Settings = settings; ConsecutiveErrors = 0; MessageHandler = new MessageHandler(this); MessageHandler.DoneMessageEvent += MessageHandler_DoneMessageEvent; MessageHandler.PlayerMessageEvent += MessageHandler_PlayerMessageEvent; MessageHandler.PlayersEvent += MessageHandler_PlayersEvent; MessageHandler.TpsMessageEvent += MessageHandler_TpsMessageEvent; MessageHandler.PlayerJoinedEvent += MessageHandler_PlayerJoinedEvent; MessageHandler.PlayerLeftEvent += MessageHandler_PlayerLeftEvent; Hub.HubConnectionEstablished += Hub_HubConnectionEstablished; Hub.KeepAlive += Hub_KeepAlive; Hub.ChatMessageReceived += Hub_ChatMessageReceived; Hub.ServerCommandReceived += Hub_ServerCommandReceived; Data = new ServerData(name: "test"); ServerRunLoop = new CancellableRunLoop(); ServerRunLoop.LoopIterationEvent += ServerRunLoop_LoopIterationEvent; DataUpdateTimer = new System.Timers.Timer(TimeSpan.FromSeconds(30).TotalMilliseconds); DataUpdateTimer.Elapsed += DataUpdateTimer_Elapsed; DataUpdateTimer.AutoReset = true; DataUpdateTimer.Enabled = true; }
public string testapi(string msg) { SignalRMessage message = new PMS.SignalRMessage("All", "testapi", msg); ServerHub hub = new ServerHub(); hub.Send(message); return("sucess"); }
public MinecraftRunner(string rootDirectory, Settings settings, CancellationToken token) { RootDirectory = rootDirectory; MinecraftServerFolder = Path.Combine(RootDirectory, MinecraftServerFolderName); Hub = new ServerHub(new Uri(settings.HubUrl)); Settings = settings; Server = new MinecraftServer(this, Hub, MinecraftServerFolder, settings); Token = token; }
public ReplyInt SpectateGame(string username, int gameID) { try { int spectatorID = service.SpectateGame(username, gameID); ServerHub.addPlayerToTableCom(username, gameID); return(new ReplyInt(true, "", spectatorID)); } catch (DomainException a) { return(new ReplyInt(false, a.Message, -1)); } }
public ReplyInt JoinGame(string username, int gameId) { try { int playerID = service.JoinGame(username, gameId); ServerHub.addPlayerToTableCom(username, gameId); return(new ReplyInt(true, "", playerID)); } catch (DomainException a) { return(new ReplyInt(false, a.Message, -1)); } }
protected override void OnStart(string[] args) { if (args.Length > 0) { Environment.CurrentDirectory = args[0]; } else { string directory = Environment.ExpandEnvironmentVariables(@"%ALLUSERSPROFILE%\MinecraftServerHub\"); Directory.CreateDirectory(directory); Environment.CurrentDirectory = directory; } hub = new ServerHub(ServiceSettings.Settings, new WindowsLog(eventLog)); hub.Start(); }
public ReplyInt CreateGame(string username, List <KeyValuePair <string, string> > pl) { List <KeyValuePair <string, int> > preferenceList = convertToInt(pl); try { int gameId = service.CreateGame(username, preferenceList); ServerHub.addPlayerToTableCom(username, gameId); return(new ReplyInt(true, "", gameId)); } catch (DomainException a) { return(new ReplyInt(false, a.Message, -1)); } }
public Reply LeaveGame(string username, int gameID) { try { if (service.LeaveGame(username, gameID)) { ServerHub.removePlayerFromTableCom(username, gameID); return(new Reply(true, "")); } return(new Reply(false, "unknow error")); } catch (DomainException a) { return(new Reply(false, (a.Message))); } }
static void Main(string[] args) { var log = new StdOutLog(); try { log.WriteInfo("Starting..."); var hub = new ServerHub(ServiceSettings.Settings, log); AppDomain.CurrentDomain.ProcessExit += (sender, e) => { hub.Stop(); Thread.Sleep(1000); }; hub.Start(); log.WriteInfo("Successfully started!"); hub.Task.GetAwaiter().GetResult(); } catch (Exception e) { log.WriteError(e.Message); } }
public ReplyInt CreateGame(string username, int gameType, int minPlayers, int maxPlayers, int minBet, int chipPolicy, int spectateGame, int buyIn) { try { List <KeyValuePair <string, int> > toSand = new List <KeyValuePair <string, int> >(); toSand.Add(new KeyValuePair <string, int>("gameType", gameType)); toSand.Add(new KeyValuePair <string, int>("minPlayers", minPlayers)); toSand.Add(new KeyValuePair <string, int>("maxPlayers", maxPlayers)); toSand.Add(new KeyValuePair <string, int>("minBet", minBet)); toSand.Add(new KeyValuePair <string, int>("chipPolicy", chipPolicy)); toSand.Add(new KeyValuePair <string, int>("spectateGame", spectateGame)); toSand.Add(new KeyValuePair <string, int>("buyIn", buyIn)); int gameId = service.CreateGame(username, toSand); ServerHub.addPlayerToTableCom(username, gameId); return(new ReplyInt(true, "", gameId)); } catch (DomainException a) { return(new ReplyInt(false, a.Message, -1)); } }
static void Main(string[] args) { log.Info("Starting...Press 'Exit' to exit."); log.Info("You can insert command with the following format: MethodName param1 param2 ..."); ///Initalize Manager ServerManager.Initalize(); ///Starting the server HostManager.Start(); string _configuredCommands = "The preconfigured actions are "; foreach (Server.Model.Action action in ServerManager.ActionScriptSettings.Actions) { _configuredCommands += string.Format("\n {0} \t with {1} parameter(s)", action.Method, action.Params.Count()); } log.Info(_configuredCommands); while (true) { string input = Console.ReadLine(); ///Exit for closing if (input == "Exit") { break; } else { ServerHub.TriggerActionScriptMethodFromUserInput(input); } } ///Stoping the server HostManager.Stop(); log.Info("Closing..."); }
private void Hub_HubConnectionEstablished(ServerHub sender) { SendServerDataUpdate(); }
private void Hub_KeepAlive(ServerHub sender) { SendServerDataUpdate(); }
public ServerController(ISpawnService spawnService, ServerHub hub) { this.spawnService = spawnService; serverHub = hub; }