static int CleanBanned(List <WorldRegion> list) { int removed = 0; foreach (WorldRegion w in list) { var rem = new List <string>(); foreach (string res in w.Residents) { var b = Banned.CheckBanned(res); if (b == null) { continue; } if ((b.BannedUntil - DateTime.Now).TotalDays < 30) { continue; } rem.Add(res); } removed += rem.Count; foreach (var r in rem) { w.Residents.Remove(r); } removed += CleanBanned(w.SubRegions); } return(removed); }
public static void IPCorrelate(Client player, string username) { lock (ipUsername) { //Add if new ip if (ipUsername.ContainsKey(player.RemoteEndPoint.Address) == false) { ipUsername.Add(player.RemoteEndPoint.Address, new List <string>()); } List <string> usernames = ipUsername[player.RemoteEndPoint.Address]; //Add if new username if (usernames.Contains(username) == false) { usernames.Add(username); } //Dont report banned players if (player.MinecraftUsername == null) { return; } foreach (string u in usernames) { if (u == player.MinecraftUsername) { continue; } BadPlayer b = Banned.GetBanHistory(u); if (b == null) { Log.WritePlayer(player, "AKA " + u); Chatting.Parser.TellAdmin(Chat.Purple + player.MinecraftUsername + Chat.Aqua + " AKA " + Chat.Yellow + u); } else { Log.WritePlayer(player, "AKA " + b); if (b.BannedUntil < DateTime.Now) { Chatting.Parser.TellAdmin(Chat.Purple + player.MinecraftUsername + Chat.Aqua + " AKA " + Chat.DarkRed + u + Chat.White + " Expired: " + b.Reason); } else { Chatting.Parser.TellAdmin(Chat.Purple + player.MinecraftUsername + Chat.Aqua + " AKA " + Chat.Red + u + Chat.White + " " + b.Reason); } } } } }
/// <summary> /// Special worlds where the entrance region matters /// such as banks and warpzones /// </summary> public void SetWorld(World w) { lock (sessionLock) { if (Phase == Phases.FinalClose) { w = World.Void; } WorldSession old = Session; Session = World.Void.Join(this); clientThread.State = "Void"; if (old != null) { old.Close("going to " + w); } WorldSession n; //Banned players BadPlayer b = Banned.CheckBanned(this); if (b == null) { n = w.Join(this); AfkSession afk = n as AfkSession; if (afk != null) { afk.OriginalWorld = old.World; } } else { n = World.HellBanned.Join(this); } //If we are denied if (n == null) { Session = World.Wait.Join(this); } else { Session = n; } clientThread.State = Session.ToString(); } }
public void BanByServer(DateTime bannedUntil, string reason) { Banned.Ban(null, MinecraftUsername, bannedUntil, reason); }
public void FromClient(PacketFromClient packet) { if (packet.PacketID == PassThrough.ID) { Session.FromClient(packet); return; } //Ping update if (packet.PacketID == KeepAlivePong.ID) { var ka = packet as KeepAlivePong; lock (pings) { if (pings.ContainsKey(ka.KeepAliveID)) { Ping = (DateTime.Now - pings[ka.KeepAliveID]).TotalMilliseconds; pings.Remove(ka.KeepAliveID); } } } //Send possessed packets SendToPossessors(packet); //Check for invalid data, hacked clients(Derp) double pitch = 0; if (packet.PacketID == PlayerPositionLookClient.ID) { pitch = ((PlayerPositionLookClient)packet).Pitch; } if (pitch > 91 || pitch < -91) { //this.Ban (null, DateTime.Now.AddMinutes (42), "Modified client"); if (Banned.CheckBanned(MinecraftUsername) == null) { Chatting.Parser.TellAdmin(Permissions.Ban, Name + Chat.Gray + " crazy head angle " + pitch.ToString("0.0")); } SendToClient(new EntityStatus(EntityID, MineProxy.Data.EntityStatuses.EntityHurt)); } if (packet.PacketID == Packets.ClientSettings.ID) { var vd = (Packets.ClientSettings)packet; this.Locale = vd.Locale; this.ViewDistance = vd.ViewDistance; } //Check for book signatures if (packet.PacketID == MCBook.ID && packet is MCBook) { var b = packet as MCBook; if (b != null) { Log.WriteBook(this, b); Debug.WriteLine("Book: " + b); //Check for signatures RuleBook.Rules.Verify(this, b); } } WorldSession s = Session; try { switch (packet.PacketID) { case ChatMessageClient.ID: Parser.ParseClient(this, (ChatMessageClient)packet); //AfkTime = DateTime.Now; return; case TabCompleteClient.ID: Parser.ParseClient(this, (TabCompleteClient)packet); return; default: s.FromClient(packet); break; } } catch (SessionClosedException sc) { SessionClosed(s, sc); } catch (IOException sc) { SessionClosed(s, sc); } #if !DEBUG catch (Exception e) { Log.Write(e, this); SessionClosed(s, e); } #endif }
public static void Main(string[] args) { //Bug workaround System.Web.Util.HttpEncoder.Current = System.Web.Util.HttpEncoder.Default; Directory.SetCurrentDirectory(MineSharp.Settings.BaseWorldsPath); Console.WriteLine(); Console.WriteLine("Starting Mineproxy: " + DateTime.Now); Log.Init(); //Init commands Commands.MainCommands.Init(); System.Threading.Thread.CurrentThread.Name = "Player Listener"; Console.CancelKeyPress += HandleConsoleCancelKeyPress; int controllerPort = 25465; #if DEBUG //Only for debugging the live server //MinecraftServer.Port = 25665; //Debug.WriteLine(MinecraftProtocol.Minecraft.Protocol); #endif //Load settings Banned.LoadBanned(); MineProxy.Regions.WarpPortalVisuals.Init(); //VoteListener.Start(); ServerCommander.Startup(); ControlListener.Start(controllerPort); BackupProxy.Start(); try { PlayerList.StartUpdater(); //SpawnRegion.Start (); Settings.Start(); QueryListener.Start(); } catch (Exception e) { Log.WriteServer(e); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } while (true) { Console.WriteLine(DateTime.Now + " Starting Main true loop"); listener = new TcpListener(IPAddress.Any, MinecraftServer.MainPort); try { listener.Start(); Console.WriteLine("Listening for players on " + MinecraftServer.MainPort); while (Active) { TcpClient client = listener.AcceptTcpClient(); if (Active == false) { break; } //Console.WriteLine ("Got incoming"); try { //check banned ip if (Banned.IsBanned(((IPEndPoint)client.Client.RemoteEndPoint).Address)) { try { client.Close(); } catch (Exception e) { Log.WriteServer("Error closing banned ip", e); } continue; } Client proxy = new VanillaClient(client.Client); proxy.Start(); } catch (SocketException) { try { client.Close(); } catch { } } } //Program is exiting here Console.WriteLine("Kicking all players: " + ShutdownMessage); foreach (Client p in PlayerList.List) { p.Kick(ShutdownMessage); } Log.Flush(); ServerCommander.Shutdown(); ControlListener.Stop(); return; #if !DEBUG } catch (Exception e) { Console.WriteLine(DateTime.Now + " Main loop error: " + e.GetType().Name + " " + e.Message); Log.WriteServer("MainClass.Main general", e); System.Threading.Thread.Sleep(500); #endif } finally { Console.WriteLine(DateTime.Now + " Main loop finally Start"); try { //Save region stats RegionLoader.Save(World.Main.Regions); Regions.WarpPortalVisuals.Stop(); } catch (Exception e) { Log.WriteServer("Main closing region stats saving", e); } Console.WriteLine(DateTime.Now + " Main loop finally End"); Environment.Exit(0); } } }
public static void LogoutPlayer(Client pp) { bool removed = false; lock (list) { removed = list.Contains(pp); list.Remove(pp); List = list.ToArray(); } if (removed) { QueueToAll(PlayerListItem.RemovePlayer(pp)); } //PlayerList.UpdateRefreshTabPlayers(); Log.WriteUsersLog(); if (removed && pp.MinecraftUsername != null && pp.Settings.Cloaked == null && Banned.CheckBanned(pp) == null && pp.MinecraftUsername != "Player") { Chatting.Parser.Say(Chat.Gray, pp.Name + " left the game"); } }
static void Welcome(Client player) { var header = new PlayerListHeaderFooter(); header.Header = new ChatJson(); header.Header.Translate = "%1$s\n%2$s"; header.Header.With = new List <ChatJson>() { new ChatJson() { Text = " ==== MCTraveler.eu ==== ", Color = "yellow", }, new ChatJson() { Text = " ======================= ", Color = "gray", }, }; header.Footer = new ChatJson() { Text = " ======================= ", Color = "gray", }; player.Queue.Queue(header); SendTabHeader(player); // if (player.ClientVersion < MinecraftServer.Version) // player.Tell(Chat.Purple, "You should upgrade to " + MinecraftServer.Version.ToString().Replace('_', '.')); /* * int count = 0; * foreach (Client p in PlayerList.List) * if (p.Cloaked == null && p.MinecraftUsername != "Player") * count ++; * if (count == 1) * player.Tell(Chat.Yellow, "Welcome, " + player.Name + " you are the first one here"); * else if (count == 2) * player.Tell(Chat.Yellow, "Welcome, " + player.Name + " there is one other player here"); * else * player.Tell(Chat.Yellow, "Welcome, " + player.Name + " there are " + (count - 1) + " other players here"); */ //Tell donor status //player.Tell(Donors.Status(player.MinecraftUsername)); string version = ""; if (player.ClientVersion < MinecraftServer.FrontendVersion) { version = Chat.Gray + "(" + player.ClientVersion.ToText() + ")"; } if (player.Settings.Cloaked == null && Banned.CheckBanned(player) == null && player.MinecraftUsername != "Player") { if (player.Uptime.TotalMinutes < 1) { Log.WritePlayer(player, "Login FirstTime"); Chatting.Parser.Say(Chat.Purple, "Welcome " + Chat.Yellow + player.Name + Chat.Purple + " from " + player.Country + version); } else { if (Donors.IsDonor(player)) { Chatting.Parser.Say(Chat.Gold, player.Name + " (donor!) joined from " + player.Country + version); } else { Chatting.Parser.Say(Chat.Yellow, player.Name + " joined from " + player.Country + version); } } //Report old bans to admin BadPlayer bp = Banned.GetBanHistory(player.MinecraftUsername); if (bp != null) { Chatting.Parser.TellAdmin("BanHistory: " + bp.BannedUntil.ToString("yyyy-MM-dd") + " " + bp.Reason); } } }
void RunController() { BinaryReader r = new BinaryReader(stream); BinaryWriter w = new BinaryWriter(stream); while (Program.Active) { int length = r.ReadInt32(); byte[] packet = r.ReadBytes(length); string json = Encoding.UTF8.GetString(packet); ControlMessage c = JsonConvert.DeserializeObject <ControlMessage>(json); if (Program.Active == false) { return; } try { //Console.WriteLine ("Got from controller " + c); if (c.Kick != null) { //Console.WriteLine ("Kick"); Client p = PlayerList.GetPlayerByUsername(c.Kick.Username); if (p != null) { p.Kick(c.Kick.Reason); } } if (c.Ban != null) { Banned.Ban(null, c.Ban.Username, c.Ban.BannedUntil, c.Ban.Reason); } if (c.Pardon != null) { Banned.Pardon(null, c.Pardon.Username); } if (c.PlayerUpdate) { //Console.WriteLine ("Update"); //Send complete player status update PlayersUpdate pu = new PlayersUpdate(); pu.List = new List <Control.Player>(); pu.MessageID = messageID; messageID += 2; foreach (Client pp in PlayerList.List) { pu.List.Add(new Control.Player(pp)); } byte[] buffer = Json.Serialize(pu); w.Write((int)buffer.Length); w.Write(buffer); w.Flush(); //Console.WriteLine ("Update Sent"); } if (c.TP != null) { var p = PlayerList.GetPlayerByUsernameOrName(c.TP.Username); if (p == null) { return; } if (c.TP.ToUsername != null) { var pTo = PlayerList.GetPlayerByUsernameOrName(c.TP.ToUsername); if (pTo == null) { return; } p.Session.World.Send("tp " + p.MinecraftUsername + " " + pTo.MinecraftUsername); continue; } if (c.TP.Position != null) { p.Warp(c.TP.Position, (Dimensions)c.TP.Dimension, Worlds.World.Main); continue; } } } catch (Exception ie) { Log.WriteServer(ie); } } }