Example #1
0
        private void SetupSkynet(CreateInstance instance = null)
        {
            if (instance == null)
            {
                instance = new CreateInstance()
                {
                    GameType = this.GameType,
                    Host     = this.Host,
                    Password = this.Password,
                    Port     = this.Port
                };
            }

            #region Realtime handlers
            // The actual method call for the connection to remote server
            var inGameMessage = skynet.On <SendIngameMessage>("IngameMessage", msg =>
            {
                if (msg.ServerName.Equals(this.InstanceName))
                {
                    if (msg.Target.Name.ToLower().Equals("all"))
                    {
                        Connection.Command("admin.say", msg.Message, msg.Target.Name.ToLower());
                        msg = null;
                    }
                    else
                    {
                        Connection.Command("admin.say", msg.Message, msg.Target.Name.ToLower(), msg.Target.TargetName);
                        msg = null;
                    }
                }
            });
            #endregion

            #region Startup calls
            skynet.Invoke <CreateInstance>("InstanceCreated", instance).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("{0} {1}", DateTime.Now, "Unable to notify thor about instance");
                    Console.WriteLine(task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("{0} {1}", DateTime.Now, "thor has been notified about instance");
                }
            }).Wait();
            #endregion
        }
Example #2
0
        private static Boolean SendMessage(Server server, String message)
        {
            var con = new RConnection();

            con.HostName          = server.Host;
            con.Port              = (ushort)server.Port;
            con.PlaintextPassword = server.Password;

            con.Connect();

            while (!con.Client.Connected)
            {
                System.Threading.Thread.Sleep(200);
            }
            con.Login();
            con.Command("admin.say", message, "all");
            System.Threading.Thread.Sleep(200);
            con.Shutdown();

            return(true);
        }