void ServerManager::checkInSet(HaxorSocket * thisSocket) { #ifdef __linux__ Command * myCommand; string inMsg; string commandName; int sockID;//thisSocket->GetID(); Client * thisClient; //cm->findClientByID(sockID); if (thisSocket->IsSet()) { sockID = thisSocket->GetID(); thisClient = cm->findClientByID(sockID); if (FD_ISSET(sockID, &inSet)) { inMsg = GetMsgFromSocket(*thisSocket); commandName = inMsg.at(0); auto search = cmdMap->find(commandName); if (search != cmdMap->end()) { myCommand = (*cmdMap)[commandName]->Clone(); myCommand->GetClient(thisClient); myCommand->Initialize(inMsg); inBox.push_back(myCommand); } } } #endif }
// Gets Called in a thread void ServerManager::threadNewConnection(int clientID) { string initMsgBuff; string cmdName; Command* tempCmd; Client * newClient = cm->findClientByID(clientID); bool success = false; cout << " and new connection thread found " << newClient->getSocketID() << endl; while (!mtx.try_lock()) { // Keep Trying! } // Mutex is Locked // Receive Login or NewAccount initMsgBuff = newClient->getSocket().Receive(); // initMsgBuff = "Login Todd Password 127.0.0.1"; // Build Command for either if (initMsgBuff.find("Login") != std::string::npos) { tempCmd = (*cmdMap)["Login"]->Clone(); } //else if (initMsgBuff.find("NewAccount") != std::string::npos) { // tempCmd = (*cmdMap)["NewAccount"]->Clone(); //} else { tempCmd = (*cmdMap)["NewAccount"]->Clone(); } tempCmd->Initialize(initMsgBuff); success = tempCmd->Execute(); // Send Result? Or have the Command return the result delete tempCmd; // LoginCheck::Execute() will find initMsgType from initMsgBuff tempCmd = (*cmdMap)["LoginCheck"]->Clone(); tempCmd->GetClient(newClient); if (success) { tempCmd->Initialize(initMsgBuff + " 1"); // Acquire the Client acquireClient(*newClient); } else { tempCmd->Initialize(initMsgBuff + " 0"); } tempCmd->Execute(); // Unlock ServerManager Data cout << "Finished handling new Connection!" << endl; mtx.unlock(); }