Beispiel #1
0
        public void HandleMessage(LobbyPlayer player, Message message)
        {
            switch (message.Type)
            {
            case "finishTutorial":
            {
                player.PlayerObject.Set("tutorialVersion", Config.TutorialVersion);
                player.PlayerObject.Save(() => player.Send("finishTutorial"));
                return;
            }

            case "acceptTerms":
            {
                player.PlayerObject.Set("termsVersion", Config.TermsVersion);
                if (player.PlayerObject.Contains("acceptTerms"))
                {
                    player.PlayerObject.Remove("acceptTerms");
                }
                player.PlayerObject.Save(() => { player.Send("acceptTerms"); });
                return;
            }

            case "checkUsername":
            {
                var name = message.GetString(0);

                this.playerIo.BigDB.Load("Usernames", name.ToLower(),
                                         result =>
                    {
                        player.Send("checkUsername", name,
                                    result == null || (!result.Contains("owner") && !result.Contains("oldowner")));
                    },
                                         error => { player.Send("checkUsername", name, false); });
                return;
            }

            case "setUsername":
            {
                var username = player.PlayerObject.GetString("name", null);
                if (username == null && player.ConnectUserId != "simpleguest")
                {
                    var newname = message.GetString(0).ToLower();
                    var test    = new Regex("[^0-9a-z]");
                    if (test.IsMatch(newname))
                    {
                        player.Send("error",
                                    "Your username contains invalid charaters. Valid charaters are 0-9 and A-Z");
                    }
                    else if (newname.Length > 20)
                    {
                        player.Send("error", "Your username cannot be more than 20 characters long.");
                    }
                    else if (newname.Length < 3)
                    {
                        player.Send("error", "Your username must be atleast 3 characters long.");
                    }

                    else if (BadWords.ContainsBadWord(newname))
                    {
                        player.Send("error", "Your username contains inappropriate words.");
                    }
                    else
                    {
                        var obj = new DatabaseObject();
                        obj.Set("owner", player.ConnectUserId);
                        this.playerIo.BigDB.CreateObject("Usernames", newname, obj,
                                                         delegate
                            {
                                Console.WriteLine("Set Username " + newname + " --> " + player.Name);
                                player.PlayerObject.Set("name", newname);
                                player.PlayerObject.Save(delegate
                                {
                                    Console.WriteLine("Username saved " + player.Name);
                                    player.Send("username", newname);
                                    player.Send("setUsername");
                                });
                            },
                                                         delegate
                            {
                                player.Send("error", "The username " + newname.ToUpper() + " is already taken!");
                            }
                                                         );
                    }
                }
                else
                {
                    player.Send("username", username);
                }
                return;
            }

            case "changeUsername":
            {
                if (player.PayVault.Has("changeusername") && player.PlayerObject.GetBool("changename", false))
                {
                    var username = player.PlayerObject.GetString("name", null);
                    if (username != null && player.ConnectUserId != "simpleguest")
                    {
                        var newname = message.GetString(0).ToLower();
                        var test    = new Regex("[^0-9a-z]");
                        if (test.IsMatch(newname))
                        {
                            player.Send("error",
                                        "Your new username contains invalid charaters. Valid charaters are 0-9 and A-Z");
                        }
                        else if (newname.Length > 20)
                        {
                            player.Send("error", "Your new username cannot be more than 20 characters long.");
                        }
                        else if (newname.Length < 3)
                        {
                            player.Send("error", "Your new username must be atleast 3 characters long.");
                        }
                        else if (BadWords.ContainsBadWord(newname))
                        {
                            player.Send("error", "Your username contains inappropriate words.");
                        }
                        else
                        {
                            var obj = new DatabaseObject();
                            obj.Set("owner", player.ConnectUserId);
                            this.playerIo.BigDB.CreateObject("Usernames", newname, obj,
                                                             delegate
                                {
                                    this.playerIo.BigDB.Load("Usernames", username,
                                                             delegate(DatabaseObject o)
                                    {
                                        o.Set("oldowner", player.ConnectUserId);
                                        o.Set("owner", "none");
                                        o.Save();

                                        Console.WriteLine("Change Username " + username + " --> " + newname);
                                        player.PlayerObject.Set("name", newname);
                                        player.PlayerObject.Set("oldname", username);
                                        player.PlayerObject.Set("changename", false);
                                        player.PlayerObject.Save(delegate
                                        {
                                            Console.WriteLine("Username saved " + player.Name);
                                            player.Send("username", newname);
                                            player.Send("changeUsername");
                                        });
                                    }
                                                             );
                                },
                                                             delegate
                                {
                                    player.Send("error", "The username " + newname.ToUpper() + " is already taken!");
                                }
                                                             );
                        }
                    }
                    else
                    {
                        player.Send("username", username);
                    }
                }
                else
                {
                    player.Send("error",
                                "You didn't purchase your name change yet!");
                    return;
                }

                return;
            }


            default:
                return;
            }
        }
Beispiel #2
0
        private void CreateCrew(Message rtn, LobbyPlayer player, string crewName)
        {
            player.PayVault.Refresh(() =>
            {
                this.client.BigDB.LoadRange("Crews", "ByCreator", new object[] { player.ConnectUserId }, null, null, 100,
                                            ownedCrews =>
                {
                    var canCreateNewCrew = player.PayVault.Count("crew") >
                                           ownedCrews.Count(it => !it.GetBool("Disbanded", false));
                    if (!canCreateNewCrew)
                    {
                        this.SendErrorReply(rtn, player, "Cannot create crew. First buy crew item in shop.");
                        return;
                    }

                    // Replace repeating spaces with one space
                    crewName = new Regex(@"[ ]{2,}").Replace(crewName, " ");

                    var test   = new Regex("^[A-Za-z0-9 ]*$");
                    var crewId = Regex.Replace(crewName, @"\s+", "").ToLower();
                    if (!test.IsMatch(crewName))
                    {
                        this.SendErrorReply(rtn, player,
                                            "Selected name contains invalid charaters. Valid charaters are 0-9, A-Z, a-z and space.");
                    }
                    else if (crewName.Length > 25)
                    {
                        this.SendErrorReply(rtn, player, "Crew name cannot be more than 25 characters long.");
                    }
                    else if (crewName.Length < 2)
                    {
                        this.SendErrorReply(rtn, player, "Crew name must be at least 2 characters long.");
                    }
                    else if (BadWords.ContainsBadWord(crewName) || BadWords.ContainsBadWord(crewId))
                    {
                        this.SendErrorReply(rtn, player, "Crew name contains inappropriate words.");
                    }
                    else
                    {
                        Console.WriteLine("Id for \"{0}\" crew = {1}", crewName, crewId);

                        var dbo = new DatabaseObject()
                                  .Set("Creator", player.ConnectUserId)
                                  .Set("Name", crewName)
                                  .Set("Subscribers", (uint)1)
                                  .Set("Ranks", new DatabaseArray()
                                       .Add(new DatabaseObject()
                                            .Set("Name", "Owner"))
                                       .Add(new DatabaseObject()
                                            .Set("Name", "Member")
                                            .Set("Powers", "0")))
                                  .Set("Members", new DatabaseObject()
                                       .Set(player.ConnectUserId, new DatabaseObject()
                                            .Set("Rank", 0)));

                        this.client.BigDB.CreateObject("Crews", crewId, dbo, newDbo =>
                        {
                            rtn.Add(true);
                            rtn.Add(newDbo.Key);

                            NotificationHelper.AddSubscription(this.client.BigDB, player.ConnectUserId,
                                                               "crew" + crewId);

                            this.client.BigDB.LoadOrCreate("CrewMembership", player.ConnectUserId, membership =>
                            {
                                membership.Set(crewId, crewName);
                                membership.Save(() => player.PlayerObject.Save(() => player.Send(rtn)));
                            });
                        }, error =>
                        {
                            // TODO: Improve error messages ?
                            this.SendErrorReply(rtn, player, error.Message);
                        });
                    }
                });
            });
        }