예제 #1
0
 private void messageTest()
 {
     PyNet.sendMessage("Platonymous.PyTK.Test", "TestMessage");
     TimeEvents.TimeOfDayChanged += (s, e) =>
     {
         foreach (MPMessage msg in PyNet.getNewMessages("Platonymous.PyTK.Test"))
         {
             string message = (string)msg.message;
             string sender  = msg.sender.Name;
             //Do Something;
         }
     };
 }
예제 #2
0
        private void registerConsoleCommands()
        {
            CcLocations.clearSpace().register();
            CcSaveHandler.cleanup().register();
            CcSaveHandler.savecheck().register();
            CcTime.skip().register();
            CcLua.runScript().register();

            new ConsoleCommand("adjustWarps", "", (s, p) =>
            {
                PyUtils.adjustWarps(p[0]);
            }).register();

            new ConsoleCommand("rebuild_objects", "", (s, e) =>
            {
                SaveHandler.RebuildAll(Game1.currentLocation.objects, Game1.currentLocation);
                SaveHandler.RebuildAll(Game1.currentLocation.terrainFeatures, Game1.currentLocation);
            }).register();

            new ConsoleCommand("allready", "confirms all players for the current readydialogue", (s, p) =>
            {
                if (!(Game1.activeClickableMenu is ReadyCheckDialog))
                {
                    Monitor.Log("No open ready check.", LogLevel.Alert);
                }
                else
                {
                    OvGame.allready = true;
                }
            }).register();

            new ConsoleCommand("send", "sends a message to all players: send [address] [message]", (s, p) =>
            {
                if (p.Length < 2)
                {
                    Monitor.Log("Missing address or message.", LogLevel.Alert);
                }
                else
                {
                    string address      = p[0];
                    List <string> parts = new List <string>(p);
                    parts.Remove(p[0]);
                    string message = String.Join(" ", p);
                    PyNet.sendMessage(address, message);
                    Monitor.Log("OK", LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("messages", "lists all new messages on a specified address: messages [address]", (s, p) =>
            {
                if (p.Length == 0)
                {
                    Monitor.Log("Missing address", LogLevel.Alert);
                }
                else
                {
                    List <MPMessage> messages = PyNet.getNewMessages(p[0]).ToList();
                    foreach (MPMessage msg in messages)
                    {
                        Monitor.Log($"From {msg.sender.Name} : {msg.message}", LogLevel.Info);
                    }

                    Monitor.Log("OK", LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("getstamina", "lists the current stamina values of all players", (s, p) =>
            {
                Monitor.Log(Game1.player.Name + ": " + Game1.player.Stamina, LogLevel.Info);
                foreach (Farmer farmer in Game1.otherFarmers.Values)
                {
                    PyNet.sendRequestToFarmer <int>("PytK.StaminaRequest", -1, farmer, (getStamina) => Monitor.Log(farmer.Name + ": " + getStamina, LogLevel.Info));
                }
            }).register();

            new ConsoleCommand("setstamina", "changes the stamina of all or a specific player. use: setstamina [playername or all] [stamina]", (s, p) =>
            {
                if (p.Length < 2)
                {
                    Monitor.Log("Missing parameter", LogLevel.Alert);
                }

                Monitor.Log(Game1.player.Name + ": " + Game1.player.Stamina, LogLevel.Info);
                Farmer farmer = null;

                farmer = Game1.otherFarmers.Find(k => k.Value.Name.Equals(p[0])).Value;


                if (farmer == null)
                {
                    Monitor.Log("Couldn't find Farmer", LogLevel.Alert);
                    return;
                }

                int i = -1;
                int.TryParse(p[1], out i);

                PyNet.sendRequestToFarmer <int>("PytK.StaminaRequest", i, farmer, (setStamina) => Monitor.Log(farmer.Name + ": " + setStamina, LogLevel.Info));
            }).register();


            new ConsoleCommand("ping", "pings all other players", (s, p) =>
            {
                foreach (Farmer farmer in Game1.otherFarmers.Values)
                {
                    long t = Game1.currentGameTime.TotalGameTime.Milliseconds;
                    PyNet.sendRequestToFarmer <bool>("PytK.Ping", t, farmer, (ping) =>
                    {
                        long r = Game1.currentGameTime.TotalGameTime.Milliseconds;
                        if (ping)
                        {
                            Monitor.Log(farmer.Name + ": " + (r - t) + "ms", LogLevel.Info);
                        }
                        else
                        {
                            Monitor.Log(farmer.Name + ": No Answer", LogLevel.Error);
                        }
                    });
                }
            }).register();

            new ConsoleCommand("syncmap", "Syncs map of a specified location to all clients. Exp.: syncmap Farm, syncmap BusStop, syncmao Town", (s, p) =>
            {
                if (p.Length < 1)
                {
                    Monitor.Log("No Location specified. ");
                }

                PyNet.syncLocationMapToAll(p[0]);
            }).register();
        }
예제 #3
0
        private void registerConsoleCommands()
        {
            CcLocations.clearSpace().register();
            CcSaveHandler.cleanup().register();
            CcSaveHandler.savecheck().register();
            CcTime.skip().register();
            CcLua.runScript().register();

            new ConsoleCommand("send", "sends a message to all players: send [address] [message]", (s, p) =>
            {
                if (p.Length < 2)
                {
                    Monitor.Log("Missing address or message.", LogLevel.Alert);
                }
                else
                {
                    string address      = p[0];
                    List <string> parts = new List <string>(p);
                    parts.Remove(p[0]);
                    string message = String.Join(" ", p);
                    PyNet.sendMessage(address, message);
                    Monitor.Log("OK", LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("messages", "lists all new messages on a specified address: messages [address]", (s, p) =>
            {
                if (p.Length == 0)
                {
                    Monitor.Log("Missing address", LogLevel.Alert);
                }
                else
                {
                    List <MPMessage> messages = PyNet.getNewMessages(p[0]).ToList();
                    foreach (MPMessage msg in messages)
                    {
                        Monitor.Log($"From {msg.sender.Name} : {msg.message}", LogLevel.Info);
                    }

                    Monitor.Log("OK", LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("getstamina", "lists the current stamina values of all players", (s, p) =>
            {
                Monitor.Log(Game1.player.Name + ": " + Game1.player.Stamina, LogLevel.Info);
                foreach (Farmer farmer in Game1.otherFarmers.Values)
                {
                    var getStamina = PyNet.sendRequestToFarmer <int>("PytK.StaminaRequest", -1, farmer);
                    getStamina.Wait();
                    Monitor.Log(farmer.Name + ": " + getStamina.Result, LogLevel.Info);
                }
            }).register();

            new ConsoleCommand("setstamina", "changes the stamina of all or a specific player. use: setstamina [playername or all] [stamina]", (s, p) =>
            {
                if (p.Length < 2)
                {
                    Monitor.Log("Missing parameter", LogLevel.Alert);
                }

                Monitor.Log(Game1.player.Name + ": " + Game1.player.Stamina, LogLevel.Info);
                Farmer farmer = null;
                try
                {
                    farmer = Game1.otherFarmers.Find(k => k.Value.Name.Equals(p[0])).Value;
                }
                catch
                {
                }

                if (farmer == null)
                {
                    Monitor.Log("Couldn't find Farmer", LogLevel.Alert);
                    return;
                }

                int i = -1;
                int.TryParse(p[1], out i);

                var setStamina = PyNet.sendRequestToFarmer <int>("PytK.StaminaRequest", i, farmer);
                setStamina.Wait();
                Monitor.Log(farmer.Name + ": " + setStamina.Result, LogLevel.Info);
            }).register();


            new ConsoleCommand("ping", "pings all other players", (s, p) =>
            {
                foreach (Farmer farmer in Game1.otherFarmers.Values)
                {
                    long t   = Game1.currentGameTime.TotalGameTime.Milliseconds;
                    var ping = PyNet.sendRequestToFarmer <bool>("PytK.Ping", t, farmer);
                    ping.Wait();

                    long r = Game1.currentGameTime.TotalGameTime.Milliseconds;
                    if (ping.Result)
                    {
                        Monitor.Log(farmer.Name + ": " + (r - t) + "ms", LogLevel.Info);
                    }
                    else
                    {
                        Monitor.Log(farmer.Name + ": No Answer", LogLevel.Error);
                    }
                }
            }).register();

            new ConsoleCommand("syncmap", "Syncs map of a specified location to all clients. Exp.: syncmap Farm, syncmap BusStop, syncmao Town", (s, p) =>
            {
                if (p.Length < 1)
                {
                    Monitor.Log("No Location specified. ");
                }

                PyNet.syncLocationMapToAll(p[0]);
            }).register();
        }