BOOL QueryBusStu(CString bus_run_ID, CString student_ID, struct bus_stu *bus_stu) { CString strSQL; strSQL = _T("SELECT * from bus_stu where bus_run_ID='"); strSQL += bus_run_ID; strSQL += _T("' and student_ID='"); strSQL += student_ID; strSQL += _T("'"); char temp_data[1024]={'\0'}; WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strSQL,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL); sqlite3_stmt *stmt = NULL; sqlite3_prepare_v2(pDB, temp_data, strlen(temp_data), &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW){ char *name = (char *)sqlite3_column_text(stmt, 0); CString strBusRunID(name); bus_stu->bus_run_ID = strBusRunID; name = (char *)sqlite3_column_text(stmt, 1); CString strStudentID(name); bus_stu->student_ID = strStudentID; name = (char *)sqlite3_column_text(stmt, 2); CString strUpStationID(name); bus_stu->up_station_ID = strUpStationID; name = (char *)sqlite3_column_text(stmt, 3); CString strUpTime(name); bus_stu->up_time = strUpTime; name = (char *)sqlite3_column_text(stmt, 4); CString strDownStationID(name); bus_stu->down_station_ID = strDownStationID; name = (char *)sqlite3_column_text(stmt, 5); CString strDownTime(name); bus_stu->down_time = strDownTime; bus_stu++; } sqlite3_finalize(stmt); return TRUE; }
std::string ASE::QueryLight() { std::stringstream reply; int iJoinedPlayers = m_pPlayerManager->CountJoined(); int iMaxPlayers = m_pMainConfig->GetMaxPlayers(); SString strPlayerCount = SString("%d/%d", iJoinedPlayers, iMaxPlayers); SString strBuildType = SString("%d", MTASA_VERSION_TYPE); SString strBuildNumber = SString("%d", MTASA_VERSION_BUILD); SFixedString<32> strPingStatusFixed; SFixedString<32> strNetRouteFixed; g_pNetServer->GetPingStatus(&strPingStatusFixed); g_pNetServer->GetNetRoute(&strNetRouteFixed); SString strPingStatus = (const char*)strPingStatusFixed; SString strNetRoute = (const char*)strNetRouteFixed; SString strUpTime("%d", (uint)(time(NULL) - m_tStartTime)); SString strHttpPort("%d", m_pMainConfig->GetHTTPPort()); uint uiExtraDataLength = (strPlayerCount.length() + 1 + strBuildType.length() + 1 + strBuildNumber.length() + 1 + strPingStatus.length() + 1 + strNetRoute.length() + 1 + strUpTime.length() + 1 + strHttpPort.length() + 1); uint uiMaxMapNameLength = 250 - uiExtraDataLength; m_strMapName = m_strMapName.Left(uiMaxMapNameLength); reply << "EYE2"; // game reply << (unsigned char)4; reply << "mta"; // port reply << (unsigned char)(m_strPort.length() + 1); reply << m_strPort; // server name reply << (unsigned char)(m_pMainConfig->GetServerName().length() + 1); reply << m_pMainConfig->GetServerName(); // game type reply << (unsigned char)(m_strGameType.length() + 1); reply << m_strGameType; // map name with backwardly compatible large player count, build type and build number reply << (unsigned char)(m_strMapName.length() + 1 + uiExtraDataLength); reply << m_strMapName; reply << (unsigned char)0; reply << strPlayerCount; reply << (unsigned char)0; reply << strBuildType; reply << (unsigned char)0; reply << strBuildNumber; reply << (unsigned char)0; reply << strPingStatus; reply << (unsigned char)0; reply << strNetRoute; reply << (unsigned char)0; reply << strUpTime; reply << (unsigned char)0; reply << strHttpPort; // version std::string temp = MTA_DM_ASE_VERSION; reply << (unsigned char)(temp.length() + 1); reply << temp; // passworded reply << (unsigned char)((m_pMainConfig->HasPassword()) ? 1 : 0); // serial verification? reply << (unsigned char)((m_pMainConfig->GetSerialVerificationEnabled()) ? 1 : 0); // players count reply << (unsigned char)std::min(iJoinedPlayers, 255); // players max reply << (unsigned char)std::min(iMaxPlayers, 255); // players CPlayer* pPlayer = NULL; // Keep the packet under 1350 bytes to try to avoid fragmentation int iBytesLeft = 1340 - (int)reply.tellp(); int iPlayersLeft = iJoinedPlayers; list<CPlayer*>::const_iterator pIter = m_pPlayerManager->IterBegin(); for (; pIter != m_pPlayerManager->IterEnd(); pIter++) { pPlayer = *pIter; if (pPlayer->IsJoined()) { // nick std::string strPlayerName = RemoveColorCodes(pPlayer->GetNick()); if (strPlayerName.length() == 0) strPlayerName = pPlayer->GetNick(); // Check if we can fit more names iBytesLeft -= strPlayerName.length() + 1; if (iBytesLeft < iPlayersLeft--) strPlayerName = ""; reply << (unsigned char)(strPlayerName.length() + 1); reply << strPlayerName.c_str(); } } return reply.str(); }