internal static bool FilterClient(WorldRegion region, Client player, Packet packet) { if (packet.PacketID != PlayerPositionLookClient.ID) return false; CoordDouble pos = player.Session.Position; //Inner region if (region.SubRegions.Count == 0) return false; WorldRegion inner = region.SubRegions[0]; //Find proportions between region edges double dOuter = pos.X - region.MinX; dOuter = Math.Min(dOuter, region.MaxX - pos.X); dOuter = Math.Min(dOuter, pos.Z - region.MinZ); dOuter = Math.Min(dOuter, region.MaxZ - pos.Z); double dInner = inner.MinX - pos.X; dInner = Math.Max(dInner, pos.X - inner.MaxX); dInner = Math.Max(dInner, inner.MinZ - pos.Z); dInner = Math.Max(dInner, pos.Z - inner.MaxZ); double frac = dOuter / (dOuter + dInner); #if DEBUG //player.Tell(frac.ToString("0.00") + ": " + dOuter + " " + dInner); #endif player.SendToClient(NightTime(frac)); return false; }
public static string Get(Client player) { if (player.Settings.Nick == null) return "no nick"; else return player.MinecraftUsername + " has nick " + player.Settings.Nick; }
public static bool Trigger(Client player, WorldRegion r) { #if DEBUG player.TellAbove("DEBUG: ", "You triggered the ban"); #else player.BanByServer(DateTime.Now.AddMinutes(30), r.Name); #endif return true; }
public Attacked(Client attacker) { By = attacker; Timestamp = DateTime.Now; if (attacker.Session.ActiveItem == null) Item = BlockID.BareHands; else Item = attacker.Session.ActiveItem.ItemID; }
public static void TellChannel(Client player) { if (player.ChatChannel == null) { player.TellSystem(Chat.Green, "You are talking to everyone"); } else { player.TellSystem(Chat.Green, "You are talking in the \"" + Chat.DarkGreen + player.ChatChannel + Chat.Green + "\" channel"); player.TellSystem(Chat.Green, "Reset using /reset"); } }
public static void SetChannel(Client player, string channel) { if (channel == "public") { player.ChatChannel = null; } else { channel = channel.Replace("§", ""); player.ChatChannel = channel; } TellChannel(player); }
public static void Prod(Client sender, Client to) { Prod(to); to.TellChat(Chat.Green, sender.Name + " gave you a friendly push"); sender.TellChat(Chat.Green, "You gave " + to.Name + " a friendly push"); VanillaSession rs = to.Session as VanillaSession; if (rs != null) { //Sender see hurt sender.Queue.Queue(new EntityStatus(rs.EID, EntityStatuses.EntityHurt)); } }
public static void Set(Client target, string nick) { if (nick.Length > 16) { return; } if (nick == "-" || nick == "reset" || nick == "clear" || nick == target.MinecraftUsername) target.Settings.Nick = null; else target.Settings.Nick = nick; target.SaveProxyPlayer(); }
public VanillaSession(VanillaWorld world, Client player) : base(player) { this.World = world; this.Vanilla = world; OreTracker = new OreTracker(player); if (player.MinecraftUsername == null) throw new ArgumentException("Player must be logged in, missing minecraftusername"); thread = Threads.Create(this, RunServerReader, WatchdogKilled); thread.User = Player.MinecraftUsername; thread.Start(); }
/// <summary> /// Read inbox messages to player /// </summary> public static void Read(Client player, string[] cmd, int iarg) { string name = PrepareName(player.MinecraftUsername); if (name == null) { player.TellSystem(Chat.Red, "Invalid name: " + player.MinecraftUsername); return; } string path = Path.Combine(dir, name); string[] messages; lock (locking) { if (File.Exists(path) == false) messages = new string[0]; else { messages = File.ReadAllLines(path); File.Delete(path); } } if (messages.Length == 0) player.TellSystem(Chat.Purple, "Inbox: no new messages"); foreach (string line in messages) { string[] parts = line.Split(new char[]{'\t'}, 3); if (parts.Length != 3) player.TellSystem(Chat.Purple, line); else { DateTime timestamp; DateTime.TryParse(parts [0], out timestamp); TimeSpan ago = DateTime.Now - timestamp; string agoString; if (ago.TotalHours < 1) agoString = ago.TotalMinutes.ToString("0") + " minutes"; else if (ago.TotalDays < 1) agoString = ago.TotalHours.ToString("0") + " hours"; else agoString = ago.TotalDays.ToString("0") + " days"; player.TellSystem(Chat.Yellow, "From " + parts [1] + " " + agoString + " ago"); player.TellSystem(Chat.White + "> ", parts [2]); } } Status(player); }
public static void LoginPlayer(Client player) { if (player.EntityID == 0 || player.MinecraftUsername == null) throw new InvalidOperationException("Can't login"); Client pl = null; lock (list) { foreach (Client p in list) { if (p == player) return; //Already logged in if (p.MinecraftUsername == player.MinecraftUsername) { list.Remove(p); pl = p; break; } } list.Add(player); List = list.ToArray(); } if (pl != null) { pl.Close("Duplicate connections"); Log.WritePlayer(player, "Disposed, Connected with another session"); } Log.WriteUsersLog(); //IP correlate IPCorrelate(player, player.MinecraftUsername); Chat.ReadFile("motd.txt", "", player); try { Welcome(player); } catch (Exception e) { Log.Write(e, player); } //PlayerList.UpdateRefreshTabPlayers(); }
public static void SetCloak(Client player, string type) { if (type == null) player.Settings.Cloaked = null; else { try { MobType mt = (MobType)Enum.Parse(typeof(MobType), type); player.Settings.Cloaked = mt.ToString(); cloakBack.Remove(player.MinecraftUsername); cloakBack.Add(player.MinecraftUsername, player.Session.Position); } catch (Exception) { player.TellSystem(Chat.DarkRed, "Unknown mob: " + type); } } player.SaveProxyPlayer(); VanillaSession rs = player.Session as VanillaSession; if (rs != null) { if (player.Settings.Cloaked == null) { SpawnPlayer spawnNamedEntity = new SpawnPlayer(rs.EID, player); spawnNamedEntity.Position = rs.Position; spawnNamedEntity.Pitch = rs.Pitch; spawnNamedEntity.Yaw = rs.Yaw; rs.World.SendToAllBut(spawnNamedEntity, player.Session); rs.Vanilla.Send("gamemode 0 " + player.MinecraftUsername); } else { PlayerList.QueueToAll(new DestroyEntities(rs.EID)); rs.Vanilla.Send("gamemode 1 " + player.MinecraftUsername); } } TellMode(player); PlayerList.UpdateTabPlayers(); }
/// <summary> /// Report inbox status to player /// </summary> public static void Status(Client player) { string name = PrepareName(player.MinecraftUsername); if (name == null) { player.TellSystem(Chat.Red, "Invalid name: " + player.MinecraftUsername); return; } string path = Path.Combine(dir, name); lock (locking) { if (File.Exists(path)) player.Inbox = File.ReadAllLines(path).Length; else player.Inbox = 0; } }
static void CloakCommand(Client player, string[] cmd, int iarg) { if (player.Admin() == false) return; if (cmd.Length < 2) { TellMode(player); return; } switch (cmd [iarg]) { case "clear": case "reset": case "normal": case "off": SetCloak(player, null); break; case "none": case "invisible": case "on": SetCloak(player, MobType.None.ToString()); break; /* case "Villager": case "Snowman": case "EnderDragon": player.Tell (Chat.Red, cmd [1] + " is disabled/not working"); return; */ case "back": if (cloakBack.ContainsKey(player.MinecraftUsername) == false) throw new ErrorException("No saved position, use /cloak first"); player.Warp(cloakBack [player.MinecraftUsername], player.Session.Dimension, World.Main); break; default: SetCloak(player, cmd [iarg]); break; } }
internal Player(Client p) { Username = p.MinecraftUsername; Uptime = p.Uptime; if (p.Session.Position != null) { Position = p.Session.Position; } Dimension = (int)p.Session.Dimension; Session = p.Session.GetType().Name; AttachedTo = p.Session.AttachedEntity; if (p.ChatEntry != null) { Chat = new ChatEntry(); Chat.Channel = p.ChatEntry.Channel; Chat.Message = p.ChatEntry.Message; Chat.Timestamp = p.ChatEntry.TimeStamp; } }
public static void TellStatTo(Client about, ClientSettings settings, Client toPlayer) { string name = "Offline"; TimeSpan uptime = settings.Uptime; if (about != null) { uptime = about.Uptime; name = about.Name; if (about.Country != null) toPlayer.TellSystem(Chat.Yellow + name + " ", "From: " + about.Country); } if (settings.FirstOnline.Ticks > 0) toPlayer.TellSystem(Chat.Yellow + name + " ", "First login: "******"0") + Chat.Blue + " days ago"); if (uptime.TotalDays > 1) toPlayer.TellSystem(Chat.Yellow + name + " ", "Online: " + uptime.TotalDays.ToString("0.0") + Chat.Blue + " days"); else toPlayer.TellSystem(Chat.Yellow + name + " ", "Online: " + uptime.TotalHours.ToString("0.0") + Chat.Blue + " hours"); toPlayer.TellSystem(Chat.Yellow + name + " ", "Walked " + settings.WalkDistance.ToString("0") + Chat.Blue + " blocks"); toPlayer.TellSystem(Chat.Yellow + name + " ", "Last Online: " + (DateTime.Now - settings.LastOnline).TotalHours.ToString("0.0") + " hours ago"); }
static void TellMode(Client player) { if (player.Settings.Cloaked != null) player.TellSystem(Chat.Purple, "You are a " + Chat.DarkAqua + player.Settings.Cloaked); else player.TellSystem(Chat.Purple, "You are yourself"); }
public static bool IsDonor(Client player) { return IsDonor(player.MinecraftUsername); }
static bool BlockClick(Client player, WindowClick wc) { player.SendToClient(new ConfirmTransactionServer(wc, false)); return true; }
public virtual void ParseTab(Client player, string[] cmd, int iarg, TabComplete tab) { if (cmd.Length < iarg) //Show all commands { CompleteCommand(player, "", tab); return; } if (cmd.Length == iarg) //Complete command { cmd [iarg - 1] = cmd [iarg - 1].ToLowerInvariant(); CompleteCommand(player, cmd [iarg - 1], tab); } if (CommandTabs.ContainsKey(cmd [iarg - 1])) { //Debug.WriteLine("TC: " + cmd.JoinFrom(0)); CommandTabs [cmd [iarg - 1]](player, cmd, iarg, tab); } }
internal static void Entering(Client player) { }
public virtual bool ParseCommand(Client player, string[] cmd, int iarg) { string command = cmd [iarg - 1]; if (player.Admin()) { if (AdminCommandParse.ContainsKey(command)) { AdminCommandParse [command](player, cmd, iarg); return true; } } if (CommandParse.ContainsKey(command)) { CommandParse [command](player, cmd, iarg); return true; } return false; }
/// <summary> /// Completes the command. /// </summary> /// <returns>The completion or null if no match was found.</returns> /// <param name="player">Player.</param> /// <param name="c">command without the leading /</param> public void CompleteCommand(Client player, string c, TabComplete tab) { if (player.Admin()) Complete(AdminStrings, c, tab); Complete(CommandStrings, c, tab); }
public static void FromServer(PacketFromServer packet, Client player) { #if DEBUG if (Show(packet)) Console.WriteLine("S-> : " + packet); #endif }
public static void Write(Exception e, Client player) { if (e == null) return; //Don't log a few items if (player != null) { if (e is EndOfStreamException) return; if (e is System.Net.Sockets.SocketException) return; } if (LogDate != DateTime.Now.Date) OpenLog(); try { exceptions.Write(Timestamp + "\t"); if (player != null) { exceptions.Write(player.MinecraftUsername + "\t"); } PrevException prev = e as PrevException; if (prev == null) { exceptions.WriteLine(e.GetType().Name + ": " + e.Message); exceptions.WriteLine(e.StackTrace); if (e.InnerException != null) Write(e.InnerException, player); exceptions.WriteLine(); } else exceptions.WriteLine(prev.Packet); //exceptions.Flush (); } catch (Exception x) { PrintException(x); PrintException(e); } }
public static void FromClient(Client c, PacketFromClient packet) { #if DEBUG if (Show(packet)) Console.WriteLine("C-> : " + packet); #endif }
static void Decloak(Client player, string[] cmd, int iarg) { SetCloak(player, null); }
internal static void Leaving(Client player) { //Resume outside time player.SendToClient(World.Main.Time); }
public static void ToClient(Client c, PacketFromServer packet) { #if DEBUG if (Show(packet)) Console.WriteLine(" ->C: " + packet.PacketBuffer.Length + ", " + packet); //System.Threading.Thread.Sleep(500); #endif }
public static void WriteChat(Client player, string channel, int receivers, string message) { if (LogDate != DateTime.Now.Date) OpenLog(); proxychat.Write(Timestamp + "\t"); proxychat.WriteLine( player.MinecraftUsername + "\t" + channel + "\t" + receivers + "\t" + message); //proxychat.Flush (); }