public User OnUserJoinedMessage(EMMServerMessage message) { // make sure user exists in database using (EMMDataContext db = Manager.GetContext) { User user = db.Users.SingleOrDefault(i => i.Username == message.Data["username"]); if (user == null) { user = CreateDefaultUser(message.Data["username"]); } // parse their current location from the join message Coord position = new Coord(message); user.LocX = position.X; user.LocY = position.Y; user.LocZ = position.Z; user.LastSeen = DateTime.Now; db.SubmitChanges(); // save the current location to the tracking table TrackUserPosition(user); return user; } }
public User OnUserJoinedMessage(EMMServerMessage message) { // make sure user exists in database using (EMMDataContext db = Manager.GetContext) { User user = db.Users.SingleOrDefault(i => i.Username == message.Data["username"]); if (user == null) { user = CreateDefaultUser(message.Data["username"]); } // parse their current location from the join message Coord position = new Coord(message); user.LocX = position.X; user.LocY = position.Y; user.LocZ = position.Z; user.LastSeen = DateTime.Now; db.SubmitChanges(); // save the current location to the tracking table TrackUserPosition(user); return(user); } }
/// <summary> /// Parses commands and executes them. Anything unknown is sent to the Minecraft server. /// </summary> /// <param name="command">Command to parse</param> public void Execute(string command) { bool executed = false; EMMServerMessage message = new EMMServerMessage(command); message.SetUser("console"); executed = mParser.ParseCommand(message); if (!executed) { SendCommand(command); } }
public Coord(EMMServerMessage message) { Coord coord; if (Coord.TryParse(message, out coord)) { mX = coord.X; mY = coord.Y; mZ = coord.Z; } else { throw new ArgumentException("Invalid message passed"); } }
public static bool TryParse(EMMServerMessage message, out Coord coord) { coord = new Coord(); double x = 0; double y = 0; double z = 0; try { double.TryParse(message.Data["LocX"], out x); double.TryParse(message.Data["LocY"], out y); double.TryParse(message.Data["LocZ"], out z); } catch { return false; } coord.X = (int)Math.Floor(x); coord.Y = (int)Math.Floor(y); coord.Z = (int)Math.Floor(z); return true; }
public static bool TryParse(EMMServerMessage message, out Coord coord) { coord = new Coord(); double x = 0; double y = 0; double z = 0; try { double.TryParse(message.Data["LocX"], out x); double.TryParse(message.Data["LocY"], out y); double.TryParse(message.Data["LocZ"], out z); } catch { return(false); } coord.X = (int)Math.Floor(x); coord.Y = (int)Math.Floor(y); coord.Z = (int)Math.Floor(z); return(true); }
/// <summary> /// Called when a user connects /// </summary> /// <param name="Message"></param> internal void OnUserJoined(EMMServerMessage Message) { Data.User user = mUserManager.OnUserJoinedMessage(Message); mOnlineUsers.Add(user.Username); }
/// <summary> /// Called whenever the server issues a message. /// </summary> /// <param name="sender"></param> /// <param name="OutLine"></param> internal void ServerOutputHandler(object sender, DataReceivedEventArgs OutLine) { if (OutLine.Data == null) { return; } EMMServerMessage M = new EMMServerMessage(OutLine.Data); switch (M.Type) { case EMMServerMessage.MessageTypes.AutoSaveEnabled: mAutoSaveEnabled = true; break; case EMMServerMessage.MessageTypes.AutoSaveDisabled: mAutoSaveEnabled = false; break; case EMMServerMessage.MessageTypes.ErrorPortBusy: OnServerError("Error starting server: port " + mMinecraftSettings.ServerPort + " in use"); ServerStatus = Status.Failed; mStatusMessage = M.Message; mPowerManager.ForceShutdown(); break; case EMMServerMessage.MessageTypes.SaveStarted: mServerSaving = true; break; case EMMServerMessage.MessageTypes.SaveComplete: mServerSaving = false; break; case EMMServerMessage.MessageTypes.StartupComplete: mOnlineUsers = new ArrayList(); OnServerStarted("Server started"); break; case EMMServerMessage.MessageTypes.UserLoggedIn: OnUserJoined(M); break; case EMMServerMessage.MessageTypes.ServerCommand: case EMMServerMessage.MessageTypes.TriedServerCommand: mParser.ParseCommand(M); break; case EMMServerMessage.MessageTypes.UserList: int oldUserCount = mOnlineUsers.Count; mOnlineUsers = new ArrayList(M.Data["userlist"].Split(',')); if (oldUserCount > 0 && mOnlineUsers.Count == 0) { OnServerReachZeroUsers(); } break; case EMMServerMessage.MessageTypes.UserLoggedOut: case EMMServerMessage.MessageTypes.UserFloating: mOnlineUsers.Remove(M.Data["username"]); if (mOnlineUsers.Count == 0) { OnServerReachZeroUsers(); } break; } // raise an InfoMessage Event too RaiseServerMessage(M.Message); }
/// <summary> /// Handle a command from the CLI. /// Commands for the server manager are prefixed with the command-character. /// </summary> /// <param name="serverMessage">The command to parse.</param> public bool ParseCommand(EMMServerMessage serverMessage) { Command command; bool executed = true; string[] args; if (serverMessage.Data.ContainsKey("command")) { args = serverMessage.Data["command"].Split(' '); } else { args = serverMessage.Message.Split(' '); } switch (args[0]) { case ("start"): mMinecraft.StartServer(); break; case ("restart"): mMinecraft.RestartServer(true); break; case ("restart now"): mMinecraft.StopServer(false); mMinecraft.StartServer(); break; case ("stop"): mMinecraft.StopServer(true); break; case ("stop now"): mMinecraft.StopServer(false); break; case ("abort"): mMinecraft.AbortPendingOperations(); break; case ("maps"): command = new MapsCommand(); command.Execute(serverMessage); break; case ("backup"): command = new BackupCommand(); command.Execute(serverMessage); break; case ("get"): command = new GetCommand(); command.Execute(serverMessage); break; default: executed = false; break; } return(executed); }
/// <summary> /// Handle a command from the CLI. /// Commands for the server manager are prefixed with the command-character. /// </summary> /// <param name="serverMessage">The command to parse.</param> public bool ParseCommand(EMMServerMessage serverMessage) { Command command; bool executed = true; string[] args; if (serverMessage.Data.ContainsKey("command")) { args = serverMessage.Data["command"].Split(' '); } else { args = serverMessage.Message.Split(' '); } switch (args[0]) { case ("start"): mMinecraft.StartServer(); break; case ("restart"): mMinecraft.RestartServer(true); break; case ("restart now"): mMinecraft.StopServer(false); mMinecraft.StartServer(); break; case ("stop"): mMinecraft.StopServer(true); break; case ("stop now"): mMinecraft.StopServer(false); break; case ("abort"): mMinecraft.AbortPendingOperations(); break; case ("maps"): command = new MapsCommand(); command.Execute(serverMessage); break; case ("backup"): command = new BackupCommand(); command.Execute(serverMessage); break; case ("get"): command = new GetCommand(); command.Execute(serverMessage); break; default: executed = false; break; } return executed; }