Exemplo n.º 1
0
        public void RemoveUserByName(string name)
        {
            FUser user = null;

            foreach (FUser u in Friends)
            {
                if (u.Name == name)
                {
                    user = u;
                    break;
                }
            }

            if (user != null)
            {
                Friends.Remove(user);
            }
        }
Exemplo n.º 2
0
 public FriendList(FUser user)
 {
     User    = user;
     Friends = new List <FUser>();
 }
Exemplo n.º 3
0
        private void FriendCommand(CommandArgs args)
        {
            //Sub-command
            //add : add a friend
            //del : delete a friend
            //list : list your friend list
            //help : Send a help message
            TPPlayer player = args.Player;

            if (player != null)
            {
                if (player.IsLoggedIn)
                {
                    if (args.Parameters.Count >= 2)
                    {
                        User       cu    = tPulse.Users.GetUserByID(player.UserID);
                        FriendList fl    = GetListOrCreate(cu);
                        string     prams = args.Parameters[0];
                        prams = prams.ToLower();

                        if (prams == "add")
                        {
                            //Add
                            string adduser = args.Parameters[1];

                            User u = tPulse.Users.GetUserByName(adduser);

                            if (u == null)
                            {
                                player.SendMessage(String.Format("Friends: {0} doesn't exists !", adduser), TextColor);
                                return;
                            }

                            if (fl.Contains(u.Name))
                            {
                                player.SendMessage(String.Format("Friends: {0} is already in your friend list", adduser), TextColor);
                                return;
                            }

                            FUser fu = new FUser(u);

                            fl.Friends.Add(fu);

                            player.SendMessage(String.Format("Friends: {0} added!", adduser), TextColor);
                        }
                        else if (prams == "del")
                        {
                            //Delete
                            string remuser = args.Parameters[1];

                            if (fl.Contains(remuser))
                            {
                                fl.RemoveUserByName(remuser);
                                player.SendMessage(String.Format("Friends: {0} deleted!", remuser), TextColor);
                            }
                            else
                            {
                                player.SendMessage(String.Format("Friends: {0} is not in your friends list", remuser), TextColor);
                            }
                        }
                    }
                    else if (args.Parameters.Count == 1)
                    {
                        string prams = args.Parameters[0];

                        if (prams == "help")
                        {
                            SendHelp(player);
                        }
                        else if (prams == "list")
                        {
                            User       cu = tPulse.Users.GetUserByID(player.UserID);
                            FriendList fl = GetListOrCreate(cu);

                            player.SendMessage(String.Format("Friends: {0} friend(s) in your list", fl.Friends.Count.ToString()), TextColor);
                            int i = 1;
                            foreach (FUser fu in fl.Friends)
                            {
                                string status = IsUserOnline(fu.ID) ? "Online" : "Offline";

                                player.SendMessage(String.Format("{0} : {1} : {2}", i.ToString(), fu.Name, status), TextColor);

                                i++;
                            }
                        }
                    }
                    else
                    {
                        player.SendMessage("Friends: Missing arguments", TextColor);
                    }
                }
                else
                {
                    player.SendMessage("Friends: You can't use friend list, because you're not logged!", TextColor);
                }
            }
        }
Exemplo n.º 4
0
        private void MessageCommand(CommandArgs args)
        {
            try
            {
                TPPlayer   player = args.Player;
                TPPlayer   dest;
                FriendList fl;
                if (player.IsLoggedIn)
                {
                    fl = FriendsList.GetListByUserID(player.UserID);
                }
                else
                {
                    return;
                }


                if (args.Parameters.Count >= 1)
                {
                    string target  = args.Parameters[0];
                    string message = "";

                    for (int i = 1; i < args.Parameters.Count; i++)
                    {
                        message += args.Parameters[i] + " ";
                    }

                    if (regexNumber.IsMatch(target))
                    {
                        //Friends number

                        int order = int.Parse(target) - 1;

                        FUser udest = fl.GetUser(order);
                        if (udest != null)
                        {
                            dest = GetOnlinePlayerById(udest.ID);

                            if (dest != null)
                            {
                                dest.SendMessage(String.Format("{0}: {1}", player.UserAccountName, message), TextColor);
                                player.SendMessage(String.Format("To {0}: {1}", dest.UserAccountName, message), TextColor);
                            }
                            else
                            {
                                player.SendMessage("Friends: this friend is not online", TextColor);
                            }
                        }
                        else
                        {
                            player.SendMessage(String.Format("Friends: {0} is not a valid friend id", order.ToString()), TextColor);
                        }
                    }
                    else
                    {
                        string name  = args.Parameters[0];
                        FUser  udest = fl.GetUser(name);
                        if (udest != null)
                        {
                            dest = GetOnlinePlayerById(udest.ID);

                            if (dest != null)
                            {
                                dest.SendMessage(String.Format("{0}: {1}", player.UserAccountName, message), TextColor);
                            }
                            else
                            {
                                player.SendMessage("Friends: this friend is not online", TextColor);
                            }
                        }
                        else
                        {
                            player.SendMessage(String.Format("Friends: {0} is not a valid friend", name), TextColor);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //put this into a log file or just remove it
                //will see
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.TargetSite);
            }
        }
Exemplo n.º 5
0
 public FriendList(FUser user)
 {
     User = user;
     Friends = new List<FUser>();
 }
Exemplo n.º 6
0
        private void FriendCommand(CommandArgs args)
        {
            //Sub-command
            //add : add a friend
            //del : delete a friend
            //list : list your friend list
            //help : Send a help message
            TPPlayer player = args.Player;

            if (player != null)
            {
                if (player.IsLoggedIn)
                {

                    if (args.Parameters.Count >= 2)
                    {
                        User cu = tPulse.Users.GetUserByID(player.UserID);
                        FriendList fl = GetListOrCreate(cu);
                        string prams = args.Parameters[0];
                        prams = prams.ToLower();

                        if (prams == "add")
                        {

                            //Add
                            string adduser = args.Parameters[1];

                            User u = tPulse.Users.GetUserByName(adduser);

                            if (u == null)
                            {
                                player.SendMessage(String.Format("Friends: {0} doesn't exists !", adduser), TextColor);
                                return;
                            }

                            if (fl.Contains(u.Name))
                            {
                                player.SendMessage(String.Format("Friends: {0} is already in your friend list", adduser), TextColor);
                                return;
                            }

                            FUser fu = new FUser(u);

                            fl.Friends.Add(fu);

                            player.SendMessage(String.Format("Friends: {0} added!", adduser), TextColor);
                        }
                        else if (prams == "del")
                        {
                            //Delete
                            string remuser = args.Parameters[1];

                            if (fl.Contains(remuser))
                            {
                                fl.RemoveUserByName(remuser);
                                player.SendMessage(String.Format("Friends: {0} deleted!", remuser), TextColor);
                            }
                            else
                            {
                                player.SendMessage(String.Format("Friends: {0} is not in your friends list", remuser), TextColor);
                            }

                        }

                    }
                    else if (args.Parameters.Count == 1)
                    {
                        string prams = args.Parameters[0];

                        if (prams == "help")
                        {
                            SendHelp(player);
                        }
                        else if (prams == "list")
                        {
                            User cu = tPulse.Users.GetUserByID(player.UserID);
                            FriendList fl = GetListOrCreate(cu);

                            player.SendMessage(String.Format("Friends: {0} friend(s) in your list", fl.Friends.Count.ToString()), TextColor);
                            int i = 1;
                            foreach (FUser fu in fl.Friends)
                            {
                                string status = IsUserOnline(fu.ID) ? "Online" : "Offline";

                                player.SendMessage(String.Format("{0} : {1} : {2}", i.ToString(), fu.Name, status), TextColor);

                                i++;
                            }
                        }
                    }
                    else
                    {
                        player.SendMessage("Friends: Missing arguments", TextColor);
                    }
                }
                else
                {
                    player.SendMessage("Friends: You can't use friend list, because you're not logged!", TextColor);
                }
            }
        }