]> jfr.im git - irc/gameservirc.git/blame - gameserv/do_register.cpp
More exciting additions to FilePlayerDAO!
[irc/gameservirc.git] / gameserv / do_register.cpp
CommitLineData
0bbd37a7 1#include "extern.h"
857510e8 2#include "options.h"
0bbd37a7 3#include "aClient.h"
4#include "player.h"
5#include "flags.h"
6#include "pouch.h"
7#include "item.h"
8#include "toplist.h"
9
10void do_register(char *u)
11{
12 char *password, *name;
13 aClient *user;
14 Player *p;
15 name = strtok(NULL, " ");
16 password = strtok(NULL, " ");
17
18 if (!name)
19 {
20 notice(s_GameServ, u, "SYNTAX: /msg <S REGISTER NAME PASSWORD");
21 }
22 else if (stricmp(name, s_GameServ) == 0)
23 {
24 notice(s_GameServ, u, "You can't use <S as a name!");
25 }
26 else if (!password)
27 {
28 notice(s_GameServ, u, "SYNTAX: /msg <S REGISTER NAME PASSWORD");
29 }
30 else if (strlen(name) > maxnicklen)
31 {
32 notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen);
33 }
34 else if (!alphaNumeric(name))
35 {
36 notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!");
37 }
38 else if ((p = findplayer(name)))
39 {
40 notice(s_GameServ, u, "%s is already registered!", name);
41 notice(s_GameServ, u, "Choose another name!");
42 }
43 else if (!(user = find(u)))
44 {
45 log("Fatal Error: Couldn't find %s in the clients list", u);
46 }
47 else if (isIgnore(user))
48 {
49#ifdef DEBUGMODE
50 log("Ignoring %s.", user->getNick());
51#endif
52 }
53 else
54 {
55 if (!is_playing(user))
56 {
57 item *tempItem;
58 unsigned long hv = iHASH((unsigned char *) name);
59
60 // First create the Player
61 user->stats = new Player();
62
63 // Set the backwards pointer
64 user->stats->setClient(user);
65
66 // Set the player's password
67 user->stats->setPassword(password);
68
69 // Set the player's name
70 user->stats->setName(name);
71
72 // Make sure they have a proper time stamp
73 updateTS(user->stats);
74
75 // Update the last login time
76 user->stats->lastlogin = time(NULL);
77
78 // Send notification of success
79 notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->getName().c_str(), password);
80 notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
81
82 // Log the new player
83 log("Nickname %s registered player %s.", u, user->stats->getName().c_str());
84
85 // Log the player in
86 setPlaying(user);
87
88 // Start the player at the beginning
89 reset(user->stats);
90
91 // Add the stick and clothes
92 tempItem = findItemByID(3001);
93 user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick
94 user->stats->inventory->addItem(tempItem)->use(user->stats); // Add Clothes
95
96 // Add the player to the list
97 players[hv].push_back(user->stats);
98
99 // Attempt to add the player to the top list
100 // The class takes care of pruning the user out if they don't deserve to be in the list
101 myToplist.insertPlayer(user->stats);
102 }
103 else
104 {
105 notice(s_GameServ, u, "Already registered. Contact a <S admin for help.");
106 }
107 }
108}