Example #1
0
        public void cmdShutdown(string message)
        {
            int secs = 0;

            if (message == "")
            {
                sendToUser((Server.shutdownSecs > -1 ? "System set to shutdown at " + DateTime.Now.AddSeconds(Server.shutdownSecs).ToString() : "System shutdown not set"), true, false, false);
            }
            else if (message.ToString() == "abort")
            {
                Server.shutdownSecs = -1;
                sendToUser("Server shutdown aborted", true, false, false);
            }
            else if (!int.TryParse(message, out secs))
            {
                sendToUser("Syntax: shutdown <abort/time in seconds>", true, false, false);
            }
            else
            {
                logToFile("System set to shut down in " + message + " seconds by " + myPlayer.UserName, "admin");
                foreach (Connection c in connections)
                {
                    if (c.socket.Connected && c.myPlayer != null)
                    {
                        c.myPlayer.SavePlayer();
                        c.Writer.Write(AnsiColour.Colorise("\r\n" + myPlayer.ColourUserName + " ^Rhas set the system to shutdown in " + formatTime(new TimeSpan(0, 0, secs)) + "!\r\n", c.myPlayer.DoColour));
                        c.Writer.Flush();
                    }
                }
                Server.Shutdown(secs);
            }
        }
Example #2
0
        public void cmdMOTD(string message)
        {
            string path = (@"files" + Path.DirectorySeparatorChar);
            string motd = AnsiColour.Colorise(loadTextFile(path + "motd.txt"));

            motd = "{bold}{cyan}---[{red}Message of the Day{cyan}]".PadRight(103, '-') + "\r\n{reset}" + motd;
            sendToUser(motd + "\r\n{bold}{cyan}" + "".PadRight(80, '-') + "{reset}\r\n", true, false, false);
        }
Example #3
0
        public void cmdScare(string message)
        {
            if (message == "")
            {
                sendToUser("Syntax: scare <player name>", true, false, false);
            }
            else
            {
                string[] target = matchPartial(message);

                if (target.Length == 0)
                {
                    sendToUser("No such user \"" + message.Substring(0, message.IndexOf(" ")) + "\"");
                }
                else if (target.Length > 1)
                {
                    sendToUser("Multiple matches found: " + target.ToString() + " - Please use more letters", true, false, false);
                }
                else if (target[0].ToLower() == myPlayer.UserName.ToLower())
                {
                    sendToUser("Trying to scare yourself?!", true, false, false);
                }
                else if (!isOnline(target[0]))
                {
                    sendToUser("User \"" + target[0] + "\" is not online", true, false, false);
                }
                else
                {
                    foreach (Connection c in connections)
                    {
                        if (c.socket.Connected && c.myPlayer != null && c.myPlayer.UserName.ToLower() == target[0].ToLower())
                        {
                            if (c.myPlayer.PlayerRank > myPlayer.PlayerRank)
                            {
                                sendToUser("Trying to scare a higher rank eh? I think not fluffy puppy!", true, false, false);
                                c.sendToUser("^R" + myPlayer.UserName + " just tried to scare you ... ^N", true, false, false);
                                return;
                            }
                            else
                            {
                                string scarefile = AnsiColour.Colorise(loadTextFile(@"files" + Path.DirectorySeparatorChar + "scare.txt"));
                                sendToStaff("[" + AppSettings.Default.AdminName.ToUpper() + "] " + c.myPlayer.UserName + " has just been scared by " + myPlayer.UserName, (int)Player.Rank.Admin, true);
                                c.sendToUser(scarefile, true, false, false);
                                c.Writer.Flush();

                                c.myPlayer.SavePlayer();
                                c.socket.Close();
                                c.OnDisconnect();

                                logToFile("[Scare] Player \"" + target[0] + "\" has just been scared by " + myPlayer.UserName, "admin");
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        private void sendToUser(string msg, string user, bool newline, bool removeColour, bool sendPrompt, bool doHistory)
        {
            foreach (Connection conn in connections)
            {
                if (conn.myPlayer != null && conn.myPlayer.UserName.ToLower() == user.ToLower() && msg != null && conn.myPlayer.CanHear(myPlayer.UserName))
                {
                    try
                    {
                        if (conn.socket.Connected)
                        {
                            string prefix = "";
                            if (conn.myPlayer != null && conn.lastSent == conn.myPlayer.Prompt && !msg.StartsWith(conn.myPlayer.Prompt) && conn.myPlayer.UserName != myPlayer.UserName)
                            {
                                prefix = "\r\n";
                            }
                            if (newline)
                            {
                                conn.Writer.WriteLine(prefix + AnsiColour.Colorise(msg, (removeColour || !conn.myPlayer.DoColour)));
                            }
                            else
                            {
                                conn.Writer.Write(prefix + AnsiColour.Colorise(msg, (removeColour || !conn.myPlayer.DoColour)));
                            }

                            conn.Writer.Flush();

                            conn.lastSent = msg;

                            if (doHistory)
                            {
                                conn.history.Add(msg);
                                if (conn.history.Count > 50)
                                {
                                    conn.history.RemoveAt(0);
                                }
                            }

                            if (sendPrompt)
                            {
                                doPrompt(user);
                            }
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        conn.socket.Close();
                        logError(ex.ToString(), "Socket write");
                        continue;
                    }
                }
            }
        }
Example #5
0
        public void cmdCCnCol(string message)
        {
            if (message == "" || message.IndexOf(" ") == -1)
            {
                sendToUser("Syntax: ccncol <channel> <colour code>", true, false, false);
            }
            else
            {
                string[] split = message.Split(new char[] { ' ' }, 2);

                if (ClubChannel.LoadChannel(split[0]) == null)
                {
                    sendToUser("Channel \"" + split[0] + "\" not found", true, false, false);
                }
                else
                {
                    clubChannels = ClubChannel.LoadAllChannels();

                    bool found = false;
                    foreach (ClubChannel c in clubChannels)
                    {
                        if (c.Name.ToLower() == split[0].ToLower())
                        {
                            found = true;
                            if (c.Owner.ToLower() != myPlayer.UserName.ToLower() && myPlayer.PlayerRank < (int)Player.Rank.Admin)
                            {
                                sendToUser("Sorry, you are not the owner of the channel", true, false, false);
                            }
                            else if (AnsiColour.Colorise(split[1], true) != "")
                            {
                                sendToUser("That is not a valid colour code");
                            }
                            else
                            {
                                c.NameColour = split[1];
                                sendToUser("Name colour set for channel \"" + c.Name + "\"", true, false, false);
                                c.SaveChannel();
                            }
                        }
                    }
                    if (!found)
                    {
                        sendToUser("Strange ... you shouldn't be here ...", true, false, false);
                    }
                    else
                    {
                        clubChannels = ClubChannel.LoadAllChannels();
                    }
                }
            }
        }
Example #6
0
 public void showMOTD(bool force)
 {
     if (myPlayer.LastLogon.DayOfYear < DateTime.Now.DayOfYear || force)
     {
         string path   = (@"files" + Path.DirectorySeparatorChar);
         string motd   = AnsiColour.Colorise(loadTextFile(path + "motd.txt"));
         string sumotd = AnsiColour.Colorise(loadTextFile(path + "sumotd.txt"));
         motd   = "{bold}{cyan}---[{red}Message of the Day{cyan}]".PadRight(103, '-') + "\r\n{reset}" + motd;
         sumotd = "\r\n{bold}{cyan}---[{green}Staff Message of the Day{cyan}]".PadRight(107, '-') + "\r\n{reset}" + sumotd;
         sendToUser(motd + (myPlayer.PlayerRank >= (int)Player.Rank.Guide ? sumotd : "") + "\r\n{bold}{cyan}" + "".PadRight(80, '-') + "{reset}\r\n", true, false, false);
     }
     else
     {
         sendToUser("\r\n", false, false, false);
     }
 }
Example #7
0
 private void sendToAll(string msg, bool newline)
 {
     foreach (Connection conn in connections)
     {
         if (conn.socket.Connected && conn.myPlayer != null && conn.myState >= 10)
         {
             try
             {
                 if (conn.myPlayer.CanHear(myPlayer.UserName))
                 {
                     conn.Writer.Write(AnsiColour.Colorise(msg, !conn.myPlayer.DoColour));
                 }
             }
             catch (Exception ex)
             {
                 logError(ex.ToString(), "Socket write");
             }
         }
     }
 }
Example #8
0
 public void cmdRestart(string message)
 {
     logToFile("System restarted by " + myPlayer.UserName, "admin");
     foreach (Connection c in connections)
     {
         try
         {
             if (c.socket.Connected && c.myPlayer != null)
             {
                 c.Writer.Write(AnsiColour.Colorise("^RSYSTEM IS RESTARTING - BACK IN A JIFFY!\r\n", c.myPlayer.DoColour));
                 c.Writer.Flush();
                 c.Writer.Close();
                 c.socket.Close();
             }
         }
         catch
         {
         }
     }
     Server.Restart();
 }
Example #9
0
 public void cmdTitle(string message)
 {
     if (message == "" || AnsiColour.Colorise(message, true) == "")
     {
         sendToUser("You remove your title", true, false, false);
         myPlayer.Title = "";
         myPlayer.SavePlayer();
     }
     else
     {
         if (AnsiColour.Colorise(message, true).Length > 40)
         {
             sendToUser("Title too long, try again", true, false, false);
         }
         else
         {
             myPlayer.Title = message + "{reset}";
             sendToUser("You change your title to read: " + myPlayer.Title, true, false, false);
             myPlayer.SavePlayer();
         }
     }
 }
Example #10
0
 public void cmdPrefix(string message)
 {
     if (message == "" || AnsiColour.Colorise(message, true) == "")
     {
         sendToUser("You remove your prefix", true, false, false);
         myPlayer.Prefix = "";
         myPlayer.SavePlayer();
     }
     else
     {
         if (AnsiColour.Colorise(message, true).Length > 10)
         {
             sendToUser("Prefix too long, try again", true, false, false);
         }
         else
         {
             myPlayer.Prefix = message + "{reset}";
             sendToUser("You change your prefix to " + myPlayer.Prefix, true, false, false);
             myPlayer.SavePlayer();
         }
     }
 }
Example #11
0
 public void cmdPrompt(string message)
 {
     if (message == "" || AnsiColour.Colorise(message, true) == "")
     {
         sendToUser("You reset your prompt", true, false, false);
         myPlayer.Prompt = AppSettings.Default.TalkerName + ">";
         myPlayer.SavePlayer();
     }
     else
     {
         if (AnsiColour.Colorise(message, true).Length > 20)
         {
             sendToUser("Prompt too long, try again", true, false, false);
         }
         else
         {
             myPlayer.Prompt = message + "{reset}>";
             sendToUser("You set your prompt to: " + myPlayer.Prompt, true, false, false);
             myPlayer.SavePlayer();
         }
     }
 }
Example #12
0
 public void cmdTagline(string message)
 {
     if (message == "" && myPlayer.Tagline == "")
     {
         sendToUser("Syntax: tagline <text>", true, false, false);
     }
     else if (message == "")
     {
         myPlayer.Tagline = "";
         myPlayer.SavePlayer();
         sendToUser("You blank your tagline", true, false, false);
     }
     else if (AnsiColour.Colorise(message, true).Length > 160)
     {
         sendToUser("Message too long - try again", true, false, false);
     }
     else
     {
         myPlayer.Tagline = message;
         myPlayer.SavePlayer();
         sendToUser("You set your tagline to: " + myPlayer.Tagline, true, false, false);
     }
 }
Example #13
0
        public void cmdKill(string message)
        {
            if (message == "")
            {
                sendToUser("Syntax: kill <player name>", true, false, false);
            }
            else
            {
                string[] target = matchPartial(message);

                if (target.Length == 0)
                {
                    sendToUser("No such user \"" + message.Substring(0, message.IndexOf(" ")) + "\"");
                }
                else if (target.Length > 1)
                {
                    sendToUser("Multiple matches found: " + target.ToString() + " - Please use more letters", true, false, false);
                }
                else if (target[0].ToLower() == myPlayer.UserName.ToLower())
                {
                    sendToUser("Trying to scare yourself?!", true, false, false);
                }
                else
                {
                    if (isOnline(target[0]))
                    {
                        foreach (Connection c in connections)
                        {
                            if (c.socket.Connected && c.myPlayer != null && c.myPlayer.UserName.ToLower() == target[0].ToLower())
                            {
                                if (c.myPlayer.PlayerRank > myPlayer.PlayerRank)
                                {
                                    sendToUser("Trying to kill a higher rank eh? I think not fluffy puppy!", true, false, false);
                                    c.sendToUser("^R" + myPlayer.UserName + " just tried to kill you ... ^N", true, false, false);
                                    return;
                                }
                                else
                                {
                                    string scarefile = AnsiColour.Colorise(loadTextFile(@"files" + Path.DirectorySeparatorChar + "kill.txt"));
                                    sendToStaff("[NUKE] " + c.myPlayer.UserName + " has just been killed by " + myPlayer.UserName, (int)Player.Rank.Admin, true);
                                    c.sendToUser(scarefile, true, false, false);
                                    c.Writer.Flush();

                                    c.socket.Close();
                                    c.OnDisconnect();
                                    return;
                                }
                            }
                        }
                    }

                    // Check to see if they were married, if so then make the other person a widow
                    Player p = Player.LoadPlayer(target[0], 0);
                    if (p.Spouse != "" && (p.maritalStatus > Player.MaritalStatus.Single && p.maritalStatus < Player.MaritalStatus.Divorced))
                    {
                        Player t = Player.LoadPlayer(p.Spouse, 0);
                        if (t != null)
                        {
                            t.Spouse        = "";
                            t.maritalStatus = Player.MaritalStatus.Widowed;
                            t.SavePlayer();
                            if (isOnline(t.UserName))
                            {
                                foreach (Connection c in connections)
                                {
                                    if (c.myPlayer != null && c.myPlayer.UserName.ToLower() == t.UserName.ToLower())
                                    {
                                        c.myPlayer = t;
                                        c.sendToUser("You have just been made a widow by " + myPlayer.UserName, true, false, false);
                                    }
                                }
                            }
                        }
                    }
                    p = null;

                    // Now need to kill the user file
                    Player.RemovePlayerFile(target[0]);
                    logToFile("[Nuke] Player \"" + target[0] + "\" has just been killed by " + myPlayer.UserName, "admin");
                }
            }
        }