]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_identify.cpp
Added the asio framework to start developing a GameServ server
[irc/gameservirc.git] / gameserv / do_identify.cpp
1 #include "extern.h"
2 #include "options.h"
3 #include "aClient.h"
4 #include "player.h"
5 #include "flags.h"
6
7 #include <list>
8 #include <algorithm>
9 using namespace std;
10
11 void do_identify(char *u)
12 {
13 char *password, *name;
14 aClient *user;
15 Player *p;
16 name = strtok(NULL, " ");
17 password = strtok(NULL, " ");
18 if (!password || !name)
19 {
20 notice(s_GameServ, u, "SYNTAX: /msg <S IDENTIFY NAME PASSWORD");
21 }
22 else if (!(user = find(u)))
23 {
24 notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
25 log("Error: aClient not found: %s", u);
26 }
27 else if (isIgnore(user))
28 {
29 #ifdef DEBUGMODE
30 log("Ignoring %s.", user->getNick());
31 #endif
32 return;
33 }
34 else if (!(p = findplayer(name)))
35 {
36 notice(s_GameServ, u, "Player %s not found", name);
37 }
38 else if (is_playing(user))
39 {
40 notice(s_GameServ, u, "You are already playing!");
41 }
42 else if (is_playing(p->getClient()) && !isAdmin(user))
43 {
44 notice(s_GameServ, u, "That player has already identified.");
45 }
46 else if (!check_password(name, password) && !isAdmin(user))
47 {
48 notice(s_GameServ, u, "Password incorrect");
49 }
50 else
51 {
52 list<Player*>::iterator iter;
53 unsigned long hv = iHASH((unsigned char *) p->getName().c_str());
54
55 iter = find(players[hv].begin(), players[hv].end(), p);
56
57 if (iter == players[hv].end())
58 {
59 notice(s_GameServ, u, "Fatal error. Contact <S Admin. Buf: %s",
60 strtok(NULL, ""));
61 return;
62 }
63 // Make sure the other user is logged out
64 logout(p->getClient());
65
66 user->stats = p;
67 p->setClient(user);
68 updateTS(p);
69
70
71 #ifdef DEBUGMODE
72 log("Player %s IRC: %s Identified", user->stats->getName().c_str(),
73 user->getNick());
74 #endif
75 //Set the playing flag
76 setPlaying(user);
77
78 // Update the last login time
79 user->stats->lastlogin = time(NULL);
80
81 notice(s_GameServ, u, "Password Accepted. Identified.");
82 showNews(u, todaysnews);
83 }
84 }