コード例 #1
0
        static void CommandBlock(SchedulerTask task)
        {
            Player p = (Player)task.UserState;

            p.IsCommandBlockRunning = true;
            if (p.SignLines[p.SignPos] != null)
            {
                Player dst = task.Interval == new TimeSpan(0, 0, 0, 0, 1) ? Player.Console : p;

                try {
                    dst.ParseMessage(p.SignLines[p.SignPos], false);
                } catch (Exception ex) {
                    p.Message("Command produces error: \"" + p.SignLines[p.SignPos] + "\"");
                    Logger.Log(LogType.Error, ex.ToString());
                }
            }

            p.LastZoneNotification = DateTime.UtcNow;
            p.SignPos++;
            if (p.SignPos >= p.SignLines.Length)
            {
                p.SignLines             = null;
                p.SignPos               = 0;
                p.IsCommandBlockRunning = false;
            }
        }
コード例 #2
0
ファイル: WorldCommands.cs プロジェクト: Rhinovex/LegendCraft
        static void JoinHandler(Player player, Command cmd)
        {
            string worldName = cmd.Next();
            if (worldName == null)
            {
                CdJoin.PrintUsage(player);
                return;
            }

            if (worldName == "-")
            {
                if (player.LastUsedWorldName != null)
                {
                    worldName = player.LastUsedWorldName;
                }
                else
                {
                    player.Message("Cannot repeat world name: you haven't used any names yet.");
                    return;
                }
            }

            World[] worlds = WorldManager.FindWorlds(player, worldName);

            if (worlds.Length > 1)
            {
                player.MessageManyMatches("world", worlds);

            }
            else if (worlds.Length == 1)
            {
                World world = worlds[0];
                player.LastUsedWorldName = world.Name;
                switch (world.AccessSecurity.CheckDetailed(player.Info))
                {
                    case SecurityCheckResult.Allowed:
                    case SecurityCheckResult.WhiteListed:
                        if (world.IsFull)
                        {
                            player.Message("Cannot join {0}&S: world is full.", world.ClassyName);
                            return;
                        }
                        player.StopSpectating();
                        if (!player.JoinWorldNow(world, true, WorldChangeReason.ManualJoin))
                        {
                            player.Message("ERROR: Failed to join world. See log for details.");
                        }
                        break;
                    case SecurityCheckResult.BlackListed:
                        player.Message("Cannot join world {0}&S: you are blacklisted.",
                                        world.ClassyName);
                        break;
                    case SecurityCheckResult.RankTooLow:
                        player.Message("Cannot join world {0}&S: must be {1}+",
                                        world.ClassyName, world.AccessSecurity.MinRank.ClassyName);
                        break;
                }

            }
            else
            {
                // no worlds found - see if player meant to type in "/Join" and not "/TP"
                Player[] players = Server.FindPlayers(player, worldName, true);
                if (players.Length == 1)
                {
                    player.LastUsedPlayerName = players[0].Name;
                    player.StopSpectating();
                    player.ParseMessage("/TP " + players[0].Name, false, true);
                }
                else
                {
                    player.MessageNoWorld(worldName);
                }
            }
        }
コード例 #3
0
        static void TPHandler( Player player, Command cmd )
        {
            string name = cmd.Next();
            if( name == null ) {
                CdTP.PrintUsage( player );
                return;
            }

            if( cmd.Next() != null ) {
                cmd.Rewind();
                int x, y, z;
                if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out z ) ) {

                    if( x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024 ) {
                        player.Message( "Coordinates are outside the valid range!" );

                    } else {
                        player.previousLocation = player.Position;
                        player.previousWorld = null;
                        player.TeleportTo( new Position {
                            X = (short)(x * 32 + 16),
                            Y = (short)(y * 32 + 16),
                            Z = (short)(z * 32 + 16),
                            R = player.Position.R,
                            L = player.Position.L
                        } );
                    }
                } else {
                    CdTP.PrintUsage( player );
                }

            } else {
                if( name == "-" ) {
                    if( player.LastUsedPlayerName != null ) {
                        name = player.LastUsedPlayerName;
                    } else {
                        player.Message( "Cannot repeat player name: you haven't used any names yet." );
                        return;
                    }
                }
                Player[] matches = Server.FindPlayers( player, name, true );
                if( matches.Length == 1 ) {
                    Player target = matches[0];
                    World targetWorld = target.World;
                    if( targetWorld == null ) PlayerOpException.ThrowNoWorld( target );

                    if( targetWorld == player.World ) {
                        player.previousLocation = player.Position;
                        player.previousWorld = null;
                        player.TeleportTo( target.Position );

                    } else {
                        switch( targetWorld.AccessSecurity.CheckDetailed( player.Info ) ) {
                            case SecurityCheckResult.Allowed:
                            case SecurityCheckResult.WhiteListed:
                                if( targetWorld.IsFull ) {
                                    player.Message( "Cannot teleport to {0}&S because world {1}&S is full.",
                                                    target.ClassyName,
                                                    targetWorld.ClassyName );
                                    return;
                                }
                                player.StopSpectating();
                                player.previousLocation = player.Position;
                                player.previousWorld = player.World;
                                player.JoinWorld( targetWorld, WorldChangeReason.Tp, target.Position );
                                break;
                            case SecurityCheckResult.BlackListed:
                                player.Message( "Cannot teleport to {0}&S because you are blacklisted on world {1}",
                                                target.ClassyName,
                                                targetWorld.ClassyName );
                                break;
                            case SecurityCheckResult.RankTooLow:
                                player.Message( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
                                                target.ClassyName,
                                                targetWorld.ClassyName,
                                                targetWorld.AccessSecurity.MinRank.ClassyName );
                                break;
                            // TODO: case PermissionType.RankTooHigh:
                        }
                    }

                } else if( matches.Length > 1 ) {
                    player.MessageManyMatches( "player", matches );

                } else {
                    // Try to guess if player typed "/TP" instead of "/Join"
                    World[] worlds = WorldManager.FindWorlds( player, name );

                    if( worlds.Length == 1 ) {
                        player.LastUsedWorldName = worlds[0].Name;
                        player.StopSpectating();
                        player.ParseMessage( "/Join " + worlds[0].Name, false, true );
                    } else {
                        player.MessageNoPlayer( name );
                    }
                }
            }
        }
コード例 #4
0
 static void FBHandler(Player player, Command cmd)
 {
     string name = cmd.Next();
     if (String.IsNullOrEmpty(name))
     {
         CdFreezeBring.PrintUsage(player);
         return;
     }
     else
     {
         Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
         if (target == null)
         {
             return;
         }
         else
         {
             player.ParseMessage("/summon " + name, false, false); //to lazy to change target's coords, so ill just summon
             target.Info.IsFrozen = true;
             target.Message("&SYou have been frozen by {0}", player.ClassyName);
             return;
         }
     }
 }
コード例 #5
0
		private static void LeBotHandler(Player player, CommandReader cmd) {
			string cmdchat = cmd.Next();
			string option = cmd.Next();
			string helper = cmd.Next();
			if (cmdchat == null) {
				player.Message(CdBot.Help);
				return;
			}
			if (option != null)
				option = option.ToLower();
			if (cmdchat != "<CalledFromChat>") {
				cmd.Rewind();
				option = cmd.Next().ToLower();
				helper = cmd.Next();
				player.ParseMessage(string.Format("Bot {0} {1}", option ?? "", helper ?? ""), (player == Player.Console));
                return;
			}
			if (player.Info.TimeSinceLastServerMessage.TotalSeconds < 5) {
				player.Info.getLeftOverTime(5, cmd);
				return;
			}
			if (option == null) {
				player.Message(CdBot.Help);
				return;
			}
            if (player.Info.TimesUsedBot == 0) {
                player.Message(
                    "&6Bot&f: This is your first time using &6Bot&s, I suggest you use \"/Help Bot\" to further understand how I work.");
            }
            bool sentMessage = true;
            switch (option) {
				case "go":
					Scheduler.NewTask(t => Server.BotMessage("5")).RunManual(TimeSpan.FromSeconds(0));
					Scheduler.NewTask(t => Server.BotMessage("4")).RunManual(TimeSpan.FromSeconds(1));
					Scheduler.NewTask(t => Server.BotMessage("3")).RunManual(TimeSpan.FromSeconds(2));
					Scheduler.NewTask(t => Server.BotMessage("2")).RunManual(TimeSpan.FromSeconds(3));
					Scheduler.NewTask(t => Server.BotMessage("1")).RunManual(TimeSpan.FromSeconds(4));
					Scheduler.NewTask(t => Server.BotMessage("Go!")).RunManual(TimeSpan.FromSeconds(5));
					break;
				case "server":
					Server.BotMessage("The name of this server is " + ConfigKey.ServerName.GetString() + ".");
					break;
				case "joke":
					FileInfo jokeList = new FileInfo("./Bot/Jokes.txt");
					string[] jokeStrings;
					if (jokeList.Exists) {
						jokeStrings = File.ReadAllLines("./Bot/Jokes.txt");
					} else {
						Server.BotMessage("I cannot tell a joke at this time!");
						return;
					}
					Random RandjokeString = new Random();
					string joker = jokeStrings[RandjokeString.Next(0, jokeStrings.Length)];
					Server.BotMessage(joker);
					break;
				case "idea":
					FileInfo adjectiveList = new FileInfo("./Bot/Adjectives.txt");
					FileInfo nounList = new FileInfo("./Bot/Nouns.txt");
					string[] adjectiveStrings;
					string[] nounStrings;
					if (adjectiveList.Exists && nounList.Exists) {
						adjectiveStrings = File.ReadAllLines("./Bot/Adjectives.txt");
						nounStrings = File.ReadAllLines("./Bot/Nouns.txt");
					} else {
						Server.BotMessage("I cannot tell you a build idea at this time!");
						return;
					}
					Random randAdjectiveString = new Random();
					Random randNounString = new Random();
					string adjective = adjectiveStrings[randAdjectiveString.Next(0, adjectiveStrings.Length)];
					string noun = nounStrings[randNounString.Next(0, nounStrings.Length)];
					string ana = "a";
					if (adjective.StartsWith("a") || adjective.StartsWith("e") || adjective.StartsWith("i") ||
						adjective.StartsWith("o") || adjective.StartsWith("u")) {
						ana = "an";
					} else if (noun.EndsWith("s")) {
						ana = "some";
					}
					Server.BotMessage("Build " + ana + " " + adjective + " " + noun);
					break;
				case "protip":
					FileInfo tipList = new FileInfo("./Bot/Protips.txt");
					string[] tipStrings;
					if (tipList.Exists) {
						tipStrings = File.ReadAllLines("./Bot/Protips.txt");
					} else {
						Server.BotMessage("I cannot tell a protip at this time!");
						return;
					}
					Random RandtipString = new Random();
					string tipper = tipStrings[RandtipString.Next(0, tipStrings.Length)];
					Server.BotMessage(tipper);
					break;
				case "time":
					TimeSpan time = player.Info.TotalTime;
					TimeSpan timenow = player.Info.TimeSinceLastLogin;
					if (helper == "total") {
						Server.BotMessage(player.ClassyName + "&f has spent a total of {0:F2} hours on this server.", time.TotalHours);
					} else {
						Server.BotMessage(player.ClassyName + "&f has played a total of {0:F2} minutes this session.", timenow.TotalMinutes);
					}
					break;
				case "promos":
					if (player.Info.Rank.Can(Permission.Promote) || player.Info.PromoCount != 0) {
						Server.BotMessage(player.ClassyName + "&f has promoted " + player.Info.PromoCount + " players.");
					} else {
						Server.BotMessage(player.ClassyName + "&f cannot promote players yet");
					}
					break;
				case "bans":
					if (player.Info.Rank.Can(Permission.Ban) || player.Info.TimesBannedOthers != 0) {
						Server.BotMessage(player.ClassyName + "&f has banned " + player.Info.TimesBannedOthers + " players.");
					} else {
						Server.BotMessage(player.ClassyName + "&f cannot ban yet");
					}
					break;
				case "kicks":
					if (player.Info.Rank.Can(Permission.Kick) || player.Info.TimesKickedOthers != 0) {
						Server.BotMessage(player.ClassyName + "&f has kicked " +
											   player.Info.TimesKickedOthers + " players.");
					} else {
						Server.BotMessage(player.ClassyName + "&f cannot kick yet");
					}
					break;
				case "blocks":
					if (helper == "total") {
						Server.BotMessage(player.ClassyName + "&f has built " + player.Info.BlocksBuilt +
											   " blocks, deleted " + player.Info.BlocksDeleted + " and drew " +
											   player.Info.BlocksDrawn + ".");
					} else {
						Server.BotMessage(player.ClassyName + "&f has built " +
											   player.Info.BlocksBuiltThisGame + " blocks and deleted " +
											   player.Info.BlocksDeletedThisGame + " blocks this session.");
					}
					break;
				case "funfact":
					FileInfo factList = new FileInfo("./Bot/Funfacts.txt");
					string[] factStrings;
					if (factList.Exists) {
						factStrings = File.ReadAllLines("./Bot/Funfacts.txt");
					} else {
						Server.BotMessage("I cannot tell a funfact at this time!");
						return;
					}
					Random RandfactString = new Random();
					string facter = factStrings[RandfactString.Next(0, factStrings.Length)];
					Server.BotMessage(facter);
					break;
				default:
                    player.Message(CdBot.Help);
                    sentMessage = false;
					break;
			}
            if (sentMessage) {
                player.Info.LastServerMessageDate = DateTime.Now;
                player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
            }
		}
コード例 #6
0
ファイル: WorldCommands.cs プロジェクト: fragmer/fCraft
        internal static void Join( Player player, Command cmd ) {
            string worldName = cmd.Next();
            if( worldName == null ) {
                cdJoin.PrintUsage( player );
                return;
            }

            World[] worlds = WorldManager.FindWorlds( worldName );

            SearchingForWorldEventArgs e = new SearchingForWorldEventArgs( player, worldName, worlds.ToList(), true );
            WorldManager.RaiseSearchingForWorldEvent( e );
            worlds = e.Matches.ToArray();

            if( worlds.Length > 1 ) {
                player.ManyMatchesMessage( "world", worlds );

            } else if( worlds.Length == 1 ) {
                World world = worlds[0];
                switch( world.AccessSecurity.CheckDetailed( player.Info ) ) {
                    case SecurityCheckResult.Allowed:
                    case SecurityCheckResult.WhiteListed:
                        if( world.IsFull ) {
                            player.Message( "Cannot join {0}&S: world is full.", world.GetClassyName() );
                            return;
                        }
                        player.StopSpectating();
                        if( !player.Session.JoinWorldNow( world, false, true ) ) {
                            player.Message( "ERROR: Failed to join world. See log for details." );
                        }
                        break;
                    case SecurityCheckResult.BlackListed:
                        player.Message( "Cannot join world {0}&S: you are blacklisted",
                                        world.GetClassyName(), world.AccessSecurity.MinRank.GetClassyName() );
                        break;
                    case SecurityCheckResult.RankTooLow:
                        player.Message( "Cannot join world {0}&S: must be {1}+",
                                        world.GetClassyName(), world.AccessSecurity.MinRank.GetClassyName() );
                        break;
                }

            } else {
                // no worlds found - see if player meant to type in "/join" and not "/tp"
                Player[] players = Server.FindPlayers( player, worldName );
                if( players.Length == 1 ) {
                    player.StopSpectating();
                    player.ParseMessage( "/tp " + players[0].Name, false );
                } else {
                    player.NoWorldMessage( worldName );
                }
            }
        }
コード例 #7
0
        static void EditHandler(Player player, Command cmd)
        {
            string option;
            string target;

            try
            {
                option = cmd.Next().ToLower();
            }
            catch (NullReferenceException)
            {
                CdEdit.PrintUsage(player);
                return;
            }

            if (option == "help")
            {
                player.Message("Options are Add and Clear.\r\n " +
                    "'/Edit Clear Swears' will completely erase all the swears so you can start from scratch.\n " +
                    "'/Edit Add Swears Monkey' will add the word 'Monkey' to the current list of swears.");
                return;
            }

            else if(option == "clear")
            {
                target = cmd.Next();
                if(string.IsNullOrEmpty(target))
                {
                    CdEdit.PrintUsage(player);
                    return;
                }

                //clear the files
                switch (target.ToLower())
                {
                    case "swears":
                        if (File.Exists(Paths.SwearWordsFileName))
                        {
                            File.Delete(Paths.SwearWordsFileName);
                        }
                        File.Create(Paths.SwearWordsFileName).Dispose();
                        player.Message("&eThe swear words for the server has been wiped.");
                        break;
                    case "rules":
                        if (File.Exists(Paths.RulesFileName))
                        {
                            File.Delete(Paths.RulesFileName);
                        }
                        File.Create(Paths.RulesFileName).Dispose();
                        player.Message("&eThe rules for the server has been wiped.");
                        break;
                    case "greeting":
                        if (File.Exists(Paths.GreetingFileName))
                        {
                            File.Delete(Paths.GreetingFileName);
                        }
                        File.Create(Paths.GreetingFileName).Dispose();
                        player.Message("&eThe greeting for the server has been wiped.");
                        break;
                    case "announcements":
                        if (File.Exists(Paths.AnnouncementsFileName))
                        {
                            File.Delete(Paths.AnnouncementsFileName);
                        }
                        File.Create(Paths.AnnouncementsFileName).Dispose();
                        player.Message("&eThe announcements for the server has been wiped.");
                        break;
                    default:
                        player.Message("&ePlease choose either 'greeting', 'rules', 'announcements' or 'swears' as an option to clear.");
                        break;
                }
                return;
            }

            else if (option == "add")
            {
                target = cmd.Next();
                if (String.IsNullOrEmpty(target))
                {
                    CdEdit.PrintUsage(player);
                    return;
                }

                //append the files
                string newItem = cmd.NextAll();
                if (String.IsNullOrEmpty(newItem))
                {
                    CdEdit.PrintUsage(player);
                    return;
                }
                switch (target.ToLower())
                {
                    case "swear":
                    case "swearwords":
                    case "swearword":
                    case "swears":
                        if (!File.Exists(Paths.SwearWordsFileName))
                        {
                            File.Create(Paths.SwearWordsFileName).Dispose();
                        }
                        using (StreamWriter sw = File.AppendText(Paths.SwearWordsFileName))
                        {
                            player.Message("&eAdded &c'{0}'&e to the list of swear words.", newItem);
                            sw.WriteLine(newItem);
                            sw.Close();
                        }
                        player.ParseMessage("/reload swears", true, false);
                        break;
                    case "rule":
                    case "rules":
                        if (!File.Exists(Paths.RulesFileName))
                        {
                            File.Create(Paths.RulesFileName).Dispose();
                        }
                        using (StreamWriter sw = File.AppendText(Paths.RulesFileName))
                        {
                            player.Message("&eAdded &c'{0}'&e to the /rules.", newItem);
                            sw.WriteLine(newItem);
                            sw.Close();
                        }
                        break;
                    case "announcement":
                    case "announcements":
                        if (!File.Exists(Paths.AnnouncementsFileName))
                        {
                            File.Create(Paths.AnnouncementsFileName).Dispose();
                        }
                        using (StreamWriter sw = File.AppendText(Paths.AnnouncementsFileName))
                        {
                            player.Message("&eAdded &c'{0}'&e to the announcements.", newItem);
                            sw.WriteLine(newItem);
                            sw.Close();
                        }
                        break;
                    case "greeting":
                        if (!File.Exists(Paths.GreetingFileName))
                        {
                            File.Create(Paths.GreetingFileName).Dispose();
                        }
                        //File.Create(Paths.GreetingFileName).Close();
                        using (StreamWriter sw = File.AppendText(Paths.GreetingFileName))
                        {
                            player.Message("&eChanged greeting to {0}.", newItem);
                            sw.WriteLine(newItem);
                            sw.Close();
                        }
                        break;
                    default:
                        player.Message("&ePlease choose either 'greeting', 'announcements', 'rules', or 'swears' as an option to add to.");
                        break;
                }
            }
            else
            {
                CdEdit.PrintUsage(player);
                return;
            }
        }
コード例 #8
0
ファイル: Chat.cs プロジェクト: Magi1053/ProCraft
 static void checkBotResponses(Player player, string rawMessage) {
     if (player.Can(Permission.UseBot)) {
         if (rawMessage.StartsWith("Bot ", StringComparison.OrdinalIgnoreCase) && rawMessage.Length < 17) {
             player.ParseMessage("/bot <CalledFromChat> " + rawMessage.Remove(0, 4), false);
         }
         double BotTime = player.Info.TimeSinceLastServerMessage.TotalSeconds;
         if (LDistance(rawMessage.ToLower(), "how do i rank up?") <= 0.25
             || LDistance(rawMessage.ToLower(), "how do we rank up") <= 0.25) {
             if (BotTime > 5) {
                 Server.BotMessage("You rank up by building something nice, preferably big. Then ask a staff member for a review.");
                 player.Info.LastServerMessageDate = DateTime.Now;
                 player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
             }
         }
         if (LDistance(rawMessage.ToLower(), "who is the owner?") <= 0.25) {
             if (BotTime > 5) {
                 PlayerInfo owner;
                 if (PlayerDB.FindPlayerInfo(ConfigKey.ServerOwner.GetString(), out owner) && owner != null) {
                     Server.BotMessage("The owner is {0}", RankManager.HighestRank.Color + owner.Name);
                 } else {
                     Server.BotMessage("The owner is {0}", RankManager.HighestRank.Color + ConfigKey.ServerOwner.GetString());
                 }
                 player.Info.LastServerMessageDate = DateTime.Now;
                 player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
             }
         }
         if (LDistance(rawMessage.ToLower(), "what is this server called?") <= 0.25
             || LDistance(rawMessage.ToLower(), "what is the name of this server?") <= 0.25) {
             if (BotTime > 5) {
                 Server.BotMessage("The server name is: " + ConfigKey.ServerName.GetString());
                 player.Info.LastServerMessageDate = DateTime.Now;
                 player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
             }
         }
         if (LDistance(rawMessage.ToLower(), "where can i build?") <= 0.25
             || LDistance(rawMessage.ToLower(), "where do we build") <= 0.25) {
             if (BotTime > 5) {
                 Server.BotMessage("You can build anywhere outside of spawn. Just not on another persons build unless they say you can. ");
                 player.Info.LastServerMessageDate = DateTime.Now;
                 player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
             }
         }
         if (LDistance(rawMessage.ToLower(), "what is my next rank?") <= 0.25 ||
             LDistance(rawMessage.ToLower(), "what rank is after this one?") <= 0.25) {
             Rank meh = player.Info.Rank.NextRankUp;
             if (BotTime > 5 && player.Info.Rank != RankManager.HighestRank) {
             tryagain:
                 if (meh.IsDonor) {
                     meh = meh.NextRankUp;
                     goto tryagain;
                 }
                 Server.BotMessage("Your next rank is: " + meh.ClassyName);
                 player.Info.LastServerMessageDate = DateTime.Now;
                 player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
             } else if (player.Info.Rank == RankManager.HighestRank) {
                 Server.BotMessage("You are already the highest rank.");
                 player.Info.LastServerMessageDate = DateTime.Now;
                 player.Info.TimesUsedBot = (player.Info.TimesUsedBot + 1);
             }
         }
     }
 }
コード例 #9
0
ファイル: Session.cs プロジェクト: TheDireMaster/fCraft
        void IoLoop()
        {
            short  x, y, h;
            byte   mode, type, opcode;
            Packet packet;

            int pollInterval = 200;
            int pollCounter  = 0;
            int packetsSent  = 0;

            try {
                LoginSequence();
                canSend = true;

                while (!canDispose)
                {
                    Thread.Sleep(1);
                    packetsSent = 0;

                    // detect player disconnect
                    if (pollCounter > pollInterval)
                    {
                        if (!client.Connected ||
                            (client.Client.Poll(1000, SelectMode.SelectRead) && client.Client.Available == 0))
                        {
                            world.log.Log("Session.IoLoop: Lost connection to {0}.", LogType.Debug, player.name);
                            return;
                        }
                        pollCounter = 0;
                    }
                    pollCounter++;

                    // send priority output to player
                    while (canSend && priorityOutputQueue.Count > 0 && packetsSent < Server.maxSessionPacketsPerTick)
                    {
                        lock ( priorityQueueLock ) {
                            packet = priorityOutputQueue.Dequeue();
                        }
                        writer.Write(packet.data);
                        packetsSent++;
                        if (packet.data[0] == (byte)OutputCodes.Disconnect)
                        {
                            world.log.Log("Session.IoLoop: Kick packet delivered to {0}.", LogType.Debug, player.name);
                            return;
                        }
                    }

                    // send output to player
                    while (canSend && outputQueue.Count > 0 && packetsSent < Server.maxSessionPacketsPerTick)
                    {
                        lock ( queueLock ) {
                            packet = outputQueue.Dequeue();
                        }
                        writer.Write(packet.data);
                        packetsSent++;
                        if (packet.data[0] == (byte)OutputCodes.Disconnect)
                        {
                            writer.Flush();
                            world.log.Log("Session.IoLoop: Kick packet delivered to {0}.", LogType.Debug, player.name);
                            return;
                        }
                    }

                    // get input from player
                    while (canReceive && client.GetStream().DataAvailable)
                    {
                        opcode = reader.ReadByte();
                        switch ((InputCodes)opcode)
                        {
                        // Message
                        case InputCodes.Message:
                            reader.ReadByte();
                            string message = ReadString();
                            if (Player.CheckForIllegalChars(message))
                            {
                                world.log.Log("Player.ParseMessage: {0} attempted to write illegal characters in chat and was kicked.",
                                              LogType.SuspiciousActivity,
                                              player.name);
                                KickNow("Illegal characters in chat.");
                                return;
                            }
                            else
                            {
                                player.ParseMessage(message, false);
                            }
                            break;

                        // Player movement
                        case InputCodes.MoveRotate:
                            reader.ReadByte();
                            Position newPos = new Position();
                            newPos.x = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            newPos.h = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            newPos.y = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            newPos.r = reader.ReadByte();
                            newPos.l = reader.ReadByte();

                            if (newPos.h < 0 || newPos.x < -32 || newPos.x >= world.map.widthX * 32 + 32 || newPos.y < -32 || newPos.y > world.map.widthY * 32 + 32)
                            {
                                world.log.Log(player.name + " was kicked for moving out of map boundaries.", LogType.SuspiciousActivity);
                                world.SendToAll(player.name + " was kicked for moving out of map boundaries.", null);
                                KickNow("Hacking detected: out of map boundaries.");
                                return;
                            }

                            Position delta = new Position(), oldPos = player.pos;
                            bool     posChanged, rotChanged;

                            if (!player.isHidden)
                            {
                                delta.Set(newPos.x - oldPos.x, newPos.y - oldPos.y, newPos.h - oldPos.h, newPos.r, newPos.l);
                                posChanged = delta.x != 0 || delta.y != 0 || delta.h != 0;
                                rotChanged = newPos.r != oldPos.r || newPos.l != oldPos.l;

                                if (player.isFrozen)
                                {
                                    if (rotChanged)
                                    {
                                        world.SendToAll(PacketWriter.MakeRotate(player.id, newPos), player);
                                        player.pos.r = newPos.r;
                                        player.pos.l = newPos.l;
                                    }
                                    if (posChanged)
                                    {
                                        SendNow(PacketWriter.MakeTeleport(255, player.pos));
                                    }
                                }
                                else
                                {
                                    if (delta.FitsIntoByte() && fullPositionUpdateCounter < fullPositionUpdateInterval)
                                    {
                                        if (posChanged && rotChanged)
                                        {
                                            world.SendToAll(PacketWriter.MakeMoveRotate(player.id, delta), player);
                                        }
                                        else if (posChanged)
                                        {
                                            world.SendToAll(PacketWriter.MakeMove(player.id, delta), player);
                                        }
                                        else if (rotChanged)
                                        {
                                            world.SendToAll(PacketWriter.MakeRotate(player.id, newPos), player);
                                        }
                                    }
                                    else if (!delta.IsZero() && !player.isFrozen)
                                    {
                                        world.SendToAll(PacketWriter.MakeTeleport(player.id, newPos), player);
                                    }
                                    player.pos = newPos;
                                    if (player.isDummySpamming)
                                    {
                                        world.cmd.standardCommands.Dummy(player, new Command("/dummy " + player.name));
                                    }
                                }

                                fullPositionUpdateCounter++;
                                if (fullPositionUpdateCounter >= fullPositionUpdateInterval)
                                {
                                    fullPositionUpdateCounter = 0;
                                }
                            }
                            break;

                        // Set tile
                        case InputCodes.SetTile:
                            x    = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            h    = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            y    = IPAddress.NetworkToHostOrder(reader.ReadInt16());
                            mode = reader.ReadByte();
                            type = reader.ReadByte();
                            if (type > 49 || x < 0 || x > world.map.widthX || y < 0 || y > world.map.widthY || h < 0 || h > world.map.height)
                            {
                                world.log.Log(player.name + " was kicked for sending bad SetTile packets.", LogType.SuspiciousActivity);
                                world.SendToAll(player.name + " was kicked for sending bad SetTile packets.", null);
                                KickNow("Hacking detected: illegal SetTile packet.");
                                return;
                            }
                            else
                            {
                                player.SetTile(x, y, h, mode == 1, (Block)type);
                            }
                            break;
                        }
                    }
                }
            } catch (ThreadAbortException) {
                world.log.Log("Session.IoLoop: Thread aborted!", LogType.Error);
            } catch (IOException ex) {
                world.log.Log("Session.IoLoop: {0}.", LogType.Warning, ex.Message);
            } catch (SocketException ex) {
                world.log.Log("Session.IoLoop: {0}.", LogType.Warning, ex.Message);
            } catch (Exception ex) {
                world.log.Log("Session.IoLoop: {0}: {1}.", LogType.Error, ex.ToString(), ex.Message);
            } finally {
                canQueue   = false;
                canSend    = false;
                canDispose = true;
            }
        }
コード例 #10
0
 static void CancelHandler( Player player, Command cmd )
 {
     if( cmd.HasNext ) {
         CdCancel.PrintUsage( player );
         return;
     }
     if( player.IsMakingSelection ) {
         player.SelectionCancel();
         player.MessageNow( "Selection cancelled." );
         player.ParseMessage("/nvm", false, false);//LOL lazy
     } else {
         player.MessageNow( "There is currently nothing to cancel." );
     }
 }
コード例 #11
0
 static void AbortAllHandler( Player player, Command cmd )
 {
     player.IsPainting = false;			// /paint
     player.ResetAllBinds();				// /bind
     player.ParseMessage( "/brush normal", false, false );  // /brush (totally not a sneaky way to do this)
     player.BuildingPortal = false;			// /portal
     player.fireworkMode = false;			// /fireworks
     player.GunMode = false;				// /gun
     player.IsRepeatingSelection = false;		// /static
     player.SelectionCancel();			// /cancel
     player.StopSpectating();			// /spectate
     player.towerMode = false;			// /tower
     player.ParseMessage( "/nvm", false, false );		// /nvm
 }
コード例 #12
0
ファイル: ChatCommands.cs プロジェクト: Magi1053/ProCraft
 private static void greetHandler(Player player, CommandReader cmd) {
     var all = Server.Players.Where(p => !p.Info.IsHidden).OrderBy(p => p.Info.TimeSinceLastLogin.ToMilliSeconds());
     if (all.Any() && all != null) {
         Player last = all.First();
         if (last == player) {
             player.Message("You were the last player to join silly");
             return;
         }
         if (player.Info.LastPlayerGreeted == last) {
             player.Message("You have to greet someone else before you can greet {0} again.", last.Name);
             return;
         }
         string message = "Welcome to " + Color.StripColors(ConfigKey.ServerName.GetString()) + ", " + last.Name + "!";
         player.ParseMessage(message, false);
         player.Info.LastServerMessageDate = DateTime.Now;
         player.Info.LastPlayerGreeted = last;
     } else {
         player.Message("Error: No one else on!");
     }
 }