![]() |
FutureHandler Class ReferenceSocketHandler implementation.
More...
|
Public Member Functions | |
FutureHandler () | |
~FutureHandler () | |
Database & | GetDatabase () |
void | DoCommand (InSocket *, const std::string &cmd, const std::string ¶ms) |
void | Talk (InSocket *, const std::string &) |
void | ShowHelp (InSocket *, const std::string &) |
void | GlobalEvent (InSocket *, const std::string &) |
std::map< SOCKET, Socket * > & | Sockets () |
Login * | GetLogin () |
void | Count (const std::string &event) |
std::string | GetDateTime () |
Command * | GetCommand (const std::string &) |
Private Attributes | |
std::list< Command * > | m_command |
Database | m_db |
Login * | m_login |
Definition at line 38 of file FutureHandler.h.
FutureHandler::FutureHandler | ( | ) |
Definition at line 56 of file FutureHandler.cpp.
References Chunk::Init(), m_command, m_db, and Chunk::Save().
00057 :EventHandler() 00058 ,m_db("future.db") 00059 ,m_login(new Login()) 00060 { 00061 m_command.push_back(new Quit()); 00062 m_command.push_back(new Who()); 00063 m_command.push_back(new Help()); 00064 m_command.push_back(new Create()); 00065 m_command.push_back(new List()); 00066 m_command.push_back(new Look()); 00067 m_command.push_back(new Setcmd()); 00068 m_command.push_back(new North()); 00069 m_command.push_back(new South()); 00070 m_command.push_back(new East()); 00071 m_command.push_back(new West()); 00072 m_command.push_back(new Fill()); 00073 m_command.push_back(new Save()); 00074 m_command.push_back(new Left()); 00075 m_command.push_back(new Right()); 00076 m_command.push_back(new Forward()); 00077 m_command.push_back(new Up()); 00078 m_command.push_back(new Down()); 00079 m_command.push_back(new Clear()); 00080 m_command.push_back(new Edge()); 00081 m_command.push_back(new Enter()); 00082 m_command.push_back(new Go()); 00083 m_command.push_back(new Map()); 00084 00085 // world setup 00086 Query q(m_db); 00087 if (!q.get_count("select count(*) from area")) 00088 { 00089 Area a(m_db, "World"); 00090 a.SetWidth(15); 00091 a.SetHeight(9); 00092 a.Save(); 00093 } 00094 if (!q.get_count("select count(*) from chunk")) 00095 { 00096 Area a(m_db, "World"); 00097 Chunk cc(m_db, a, 1000, 1000, 0); 00098 cc.Init(NULL, 1000, 1000, 0, ' '); 00099 cc.Save(); 00100 } 00101 }
FutureHandler::~FutureHandler | ( | ) |
Database& FutureHandler::GetDatabase | ( | ) | [inline] |
Definition at line 44 of file FutureHandler.h.
References m_db.
Referenced by DoCommand(), ShowHelp(), and Talk().
00044 { return m_db; }
void FutureHandler::DoCommand | ( | InSocket * | , | |
const std::string & | cmd, | |||
const std::string & | params | |||
) |
Definition at line 188 of file FutureHandler.cpp.
References GetCommand(), Command::GetCommandFromChar(), GetDatabase(), Player::IsWizard(), and m_command.
00189 { 00190 Command *match = NULL; 00191 if (cmd.size() == 1) 00192 { 00193 match = Command::GetCommandFromChar(cmd[0]); 00194 } 00195 if (match) 00196 { 00197 Player pl(from -> GetDatabase(),from -> GetAccountName()); 00198 if (!match -> NeedWiz() || pl.IsWizard()) 00199 { 00200 Parse pa(params); 00201 std::string arg = pa.getword(); 00202 std::string complete; 00203 if (match -> CheckArgument(from, arg, complete)) 00204 { 00205 match -> Execute(from, complete, pa); 00206 } 00207 return; 00208 } 00209 } 00210 int score = 0; 00211 int count = 0; 00212 for (std::list<Command *>::iterator it = m_command.begin(); it != m_command.end(); it++) 00213 { 00214 Command *p = *it; 00215 int i = p -> Match(from, cmd, params); 00216 score = (i > score) ? i : score; 00217 if (i) 00218 { 00219 match = p; 00220 count++; 00221 } 00222 if (score == 2) 00223 { 00224 break; 00225 } 00226 } 00227 if (score == 1 && count > 1) 00228 { 00229 from -> Send("Ambiguous command.\n"); 00230 for (std::list<Command *>::iterator it = m_command.begin(); it != m_command.end(); it++) 00231 { 00232 Command *p = *it; 00233 if (p -> Match(from, cmd, params) == 1) 00234 { 00235 from -> Send(" " + p -> GetCommand() + "\n"); 00236 } 00237 } 00238 from -> SetPrompt(); 00239 } 00240 else 00241 if (score == 2 || (score == 1 && count == 1)) 00242 { 00243 Parse pa(params); 00244 std::string arg = pa.getword(); 00245 std::string complete; 00246 if (match -> CheckArgument(from, arg, complete)) 00247 { 00248 match -> Execute(from, complete, pa); 00249 } 00250 } 00251 else 00252 { 00253 from -> Send("Huh?\n"); 00254 from -> SetPrompt(); 00255 } 00256 }
void FutureHandler::Talk | ( | InSocket * | , | |
const std::string & | ||||
) |
Definition at line 117 of file FutureHandler.cpp.
References GetDatabase(), and Player::GetDisplayName().
00118 { 00119 size_t i = 0; 00120 while (i < line.size() && line[i] == ' ') 00121 i++; 00122 std::string does; 00123 if (line.size() > 2 && line.substr(line.size() - 2) == ":)") 00124 { 00125 does = "smiles and says"; 00126 from -> Send("You smile and say '" + line + "&n'.\n"); 00127 } 00128 else 00129 if (line.size() > 2 && line.substr(line.size() - 2) == ";)") 00130 { 00131 does = "flirts and says"; 00132 from -> Send("You flirt and say '" + line + "&n'.\n"); 00133 } 00134 else 00135 if (line.size() > 2 && line.substr(line.size() - 2) == "!!") 00136 { 00137 does = "shouts"; 00138 from -> Send("You shout '" + line + "&n'.\n"); 00139 } 00140 else 00141 if (line.substr(line.size() - 1) == "?") 00142 { 00143 does = "asks"; 00144 from -> Send("You ask '" + line + "&n'.\n"); 00145 } 00146 else 00147 if (line.substr(line.size() - 1) == "!") 00148 { 00149 does = "exclaims"; 00150 from -> Send("You exclaim '" + line + "&n'.\n"); 00151 } 00152 else 00153 { 00154 does = "says"; 00155 from -> Send("You say '" + line + "&n'.\n"); 00156 } 00157 Player pl(from -> GetDatabase(),from -> GetAccountName()); 00158 std::string talk = "\n" + pl.GetDisplayName() + " " + does + " '" + line.substr(i) + "&n'.\n"; 00159 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) 00160 { 00161 Socket *p0 = (*it).second; 00162 InSocket *p = dynamic_cast<InSocket *>(p0); 00163 if (p && p != from) 00164 { 00165 p -> Send(talk); 00166 p -> SendPrompt(); 00167 } 00168 } 00169 }
void FutureHandler::ShowHelp | ( | InSocket * | , | |
const std::string & | ||||
) |
Definition at line 259 of file FutureHandler.cpp.
References GetCommand(), GetDatabase(), Player::IsWizard(), and m_command.
00260 { 00261 std::map<std::string,std::map<std::string,Command *> > mmap; 00262 Player pl(from -> GetDatabase(),from -> GetAccountName()); 00263 for (std::list<Command *>::iterator it = m_command.begin(); it != m_command.end(); it++) 00264 { 00265 Command *cc = *it; 00266 if (!cc -> NeedWiz() || pl.IsWizard()) 00267 { 00268 mmap[cc -> Category()][cc -> GetCommand()] = cc; 00269 } 00270 } 00271 for (std::map<std::string,std::map<std::string,Command *> >::iterator it = mmap.begin(); it != mmap.end(); it++) 00272 { 00273 std::string category = (*it).first; 00274 std::map<std::string,Command *>& ref = (*it).second; 00275 from -> Send("&W" + category + "&n\n"); 00276 for (std::map<std::string,Command *>::iterator it = ref.begin(); it != ref.end(); it++) 00277 { 00278 std::string command = (*it).first; 00279 Command *cc = (*it).second; 00280 strbool_m& ref = cc -> GetArguments(); 00281 std::string charstr; 00282 std::string argstr; 00283 std::string descr; 00284 if (cc -> GetCommandChar()) 00285 { 00286 charstr = " &g(&y"; 00287 charstr += cc -> GetCommandChar(); 00288 charstr += "&g)&n"; 00289 } 00290 for (strbool_m::iterator it = ref.begin(); it != ref.end(); it++) 00291 { 00292 std::string arg = (*it).first; 00293 bool need_wiz = (*it).second; 00294 if (!need_wiz || pl.IsWizard()) 00295 { 00296 if (argstr.size()) 00297 argstr += "&g|&y" + arg; 00298 else 00299 argstr = " &g[&y" + arg; 00300 } 00301 } 00302 if (argstr.size()) 00303 argstr += "&g]&n"; 00304 if (cc -> Description().size()) 00305 descr = " - &M" + cc -> Description(); 00306 from -> Send(" &G" + command + charstr + argstr + descr + "&n\n"); 00307 } 00308 } 00309 }
void FutureHandler::GlobalEvent | ( | InSocket * | , | |
const std::string & | ||||
) |
Definition at line 172 of file FutureHandler.cpp.
00173 { 00174 std::string talk = "\n" + s + "\n"; 00175 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) 00176 { 00177 Socket *p0 = (*it).second; 00178 InSocket *p = dynamic_cast<InSocket *>(p0); 00179 if (p && p != from) 00180 { 00181 p -> Send(talk); 00182 p -> SendPrompt(); 00183 } 00184 } 00185 }
std::map<SOCKET,Socket *>& FutureHandler::Sockets | ( | ) | [inline] |
Login* FutureHandler::GetLogin | ( | ) | [inline] |
void FutureHandler::Count | ( | const std::string & | event | ) |
Definition at line 312 of file FutureHandler.cpp.
References db::Eventcount::count, db::Eventcount::event_name, m_db, and db::Eventcount::save().
00313 { 00314 db::Eventcount ec(m_db, event); 00315 ec.event_name = event; 00316 ec.count++; 00317 ec.save(); 00318 }
std::string FutureHandler::GetDateTime | ( | ) |
Definition at line 321 of file FutureHandler.cpp.
00322 { 00323 time_t t = time(NULL); 00324 struct tm *tp = localtime(&t); 00325 char dt[40]; 00326 sprintf(dt, "%d-%02d-%02d %02d:%02d:%02d", tp -> tm_year + 1900, tp -> tm_mon + 1, 00327 tp -> tm_mday, tp -> tm_hour, tp -> tm_min, tp -> tm_sec); 00328 return dt; 00329 }
Command * FutureHandler::GetCommand | ( | const std::string & | ) |
Definition at line 332 of file FutureHandler.cpp.
References m_command.
Referenced by DoCommand(), and ShowHelp().
00333 { 00334 for (std::list<Command *>::iterator it = m_command.begin(); it != m_command.end(); it++) 00335 { 00336 Command *cc = *it; 00337 if (cc -> GetCommand() == x) 00338 return cc; 00339 } 00340 return NULL; 00341 }
std::list<Command *> FutureHandler::m_command [private] |
Definition at line 61 of file FutureHandler.h.
Referenced by DoCommand(), FutureHandler(), GetCommand(), ShowHelp(), and ~FutureHandler().
Database FutureHandler::m_db [private] |
Definition at line 62 of file FutureHandler.h.
Referenced by Count(), FutureHandler(), and GetDatabase().
Login* FutureHandler::m_login [private] |