BYTEARRAY CGameProtocol :: SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Version, BYTEARRAY mapGameType, BYTEARRAY mapFlags, BYTEARRAY mapWidth, BYTEARRAY mapHeight, string gameName, string hostName, uint32_t upTime, string mapPath, BYTEARRAY mapCRC, uint32_t slotsTotal, uint32_t slotsOpen, uint16_t port, uint32_t hostCounter, uint32_t entryKey ) { unsigned char ProductID_ROC[] = { 51, 82, 65, 87 }; // "WAR3" unsigned char ProductID_TFT[] = { 80, 88, 51, 87 }; // "W3XP" unsigned char Version[] = { war3Version, 0, 0, 0 }; unsigned char Unknown[] = { 1, 0, 0, 0 }; BYTEARRAY packet; if( mapGameType.size( ) == 4 && mapFlags.size( ) == 4 && mapWidth.size( ) == 2 && mapHeight.size( ) == 2 && !gameName.empty( ) && !hostName.empty( ) && !mapPath.empty( ) && mapCRC.size( ) == 4 ) { // make the stat string BYTEARRAY StatString; UTIL_AppendByteArrayFast( StatString, mapFlags ); StatString.push_back( 0 ); UTIL_AppendByteArrayFast( StatString, mapWidth ); UTIL_AppendByteArrayFast( StatString, mapHeight ); UTIL_AppendByteArrayFast( StatString, mapCRC ); UTIL_AppendByteArrayFast( StatString, mapPath ); UTIL_AppendByteArrayFast( StatString, hostName ); StatString.push_back( 0 ); StatString = UTIL_EncodeStatString( StatString ); // make the rest of the packet packet.push_back( W3GS_HEADER_CONSTANT ); // W3GS header constant packet.push_back( W3GS_GAMEINFO ); // W3GS_GAMEINFO packet.push_back( 0 ); // packet length will be assigned later packet.push_back( 0 ); // packet length will be assigned later if( TFT ) UTIL_AppendByteArray( packet, ProductID_TFT, 4 ); // Product ID (TFT) else UTIL_AppendByteArray( packet, ProductID_ROC, 4 ); // Product ID (ROC) UTIL_AppendByteArray( packet, Version, 4 ); // Version UTIL_AppendByteArray( packet, hostCounter, false ); // Host Counter UTIL_AppendByteArray( packet, entryKey, false ); // Entry Key UTIL_AppendByteArrayFast( packet, gameName ); // Game Name packet.push_back( 0 ); // ??? (maybe game password) UTIL_AppendByteArrayFast( packet, StatString ); // Stat String packet.push_back( 0 ); // Stat String null terminator (the stat string is encoded to remove all even numbers i.e. zeros) UTIL_AppendByteArray( packet, slotsTotal, false ); // Slots Total UTIL_AppendByteArrayFast( packet, mapGameType ); // Game Type UTIL_AppendByteArray( packet, Unknown, 4 ); // ??? UTIL_AppendByteArray( packet, slotsOpen, false ); // Slots Open UTIL_AppendByteArray( packet, upTime, false ); // time since creation UTIL_AppendByteArray( packet, port, false ); // port AssignLength( packet ); } else CONSOLE_Print( "[GAMEPROTO] invalid parameters passed to SEND_W3GS_GAMEINFO" ); // DEBUG_Print( "SENT W3GS_GAMEINFO" ); // DEBUG_Print( packet ); return packet; }
/***************************************************************************//** * @brief Sets the output value of PD_n pin. * * @param param[0] - value to be set for PD_n pin. * * @return None. *******************************************************************************/ void SetPdPin(double* param, char paramNo) // "pdPin=" command { unsigned char status = 0; /* Check if the parameter is valid */ if(paramNo >= 1) { if(param[0] < 0) { param[0] = 0; } else { if(param[0] > 1) { param[0] = 1; } } status = (unsigned char) param[0]; if (status == 0) { AD5570_PD_LOW; pd_n = 0; } else { if (status == 1) { AD5570_PD_HIGH; pd_n = 1; } } /* Send feedback to user */ CONSOLE_Print("%s%d\r\n",(char*)cmdList[6], status); } else { /* Display error messages */ CONSOLE_Print("Invalid parameter!\r\n"); CONSOLE_Print("%s%s\r\n", (char*)cmdList[6], (char*)cmdDescription[6]); CONSOLE_Print("Example: %s\r\n", (char*)cmdExample[6]); } }
/***************************************************************************//** * @brief Resets the device. * * @return None. *******************************************************************************/ void DoReset(double* param, char paramNo) /*!< "reset!" command */ { /*!< Resets the device(software reset). */ measureSetting = 0; ADXL362_SoftwareReset(); /*!< Send feedback to user */ CONSOLE_Print("Device was reset.\r\n"); }
BYTEARRAY CGameProtocol :: SEND_W3GS_START_LAG( vector<CGamePlayer *> players, bool loadInGame ) { BYTEARRAY packet; unsigned char NumLaggers = 0; for( vector<CGamePlayer *> :: iterator i = players.begin( ); i != players.end( ); i++ ) { if( loadInGame ) { if( !(*i)->GetFinishedLoading( ) ) NumLaggers++; } else { if( (*i)->GetLagging( ) ) NumLaggers++; } } if( NumLaggers > 0 ) { packet.push_back( W3GS_HEADER_CONSTANT ); // W3GS header constant packet.push_back( W3GS_START_LAG ); // W3GS_START_LAG packet.push_back( 0 ); // packet length will be assigned later packet.push_back( 0 ); // packet length will be assigned later packet.push_back( NumLaggers ); for( vector<CGamePlayer *> :: iterator i = players.begin( ); i != players.end( ); i++ ) { if( loadInGame ) { if( !(*i)->GetFinishedLoading( ) ) { packet.push_back( (*i)->GetPID( ) ); UTIL_AppendByteArray( packet, (uint32_t)0, false ); } } else { if( (*i)->GetLagging( ) ) { packet.push_back( (*i)->GetPID( ) ); UTIL_AppendByteArray( packet, GetTicks( ) - (*i)->GetStartedLaggingTicks( ), false ); } } } AssignLength( packet ); } else CONSOLE_Print( "[GAMEPROTO] no laggers passed to SEND_W3GS_START_LAG" ); // DEBUG_Print( "SENT W3GS_START_LAG" ); // DEBUG_Print( packet ); return packet; }
CRemoteConsole :: CRemoteConsole( ) { CONSOLE_Print( "[RCON] Remote Console 1.5 loading" ); m_UDPSocket = new QUdpSocket(this); connect(m_UDPSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); // lookup "localhost" for later use //bool lookup_success = (inet_aton("localhost", &localhost) == 1); }
/***************************************************************************//** * @brief Displays the input voltage in [mV]. * * @return None. *******************************************************************************/ void GetVoltage(double* param, char paramNo) // "voltage?" command { float vin = 0; vin = ad7920_GetVoltage(VREF); vin = (vin / GAIN) * 1000; /* Send feedback to user */ CONSOLE_Print("Voltage=%.3f[mV].\r\n", vin); }
/***************************************************************************//** * @brief Internal function for displaying all the command with its description. * * @return None. *******************************************************************************/ void DisplayCmdList() { unsigned char displayCmd; for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) { CONSOLE_Print("%s - %s\r\n", (char*)cmdList[displayCmd].name, \ (char*)cmdList[displayCmd].description); } }
/***************************************************************************//** * @brief Displays last written value to the Offset Adjust register. * * @return None. *******************************************************************************/ void GetOffset(double* param, char paramNo) // "offset?" command { int value = 0; offsetReg = AD5421_GetOffset(); /* Calculate offset according to the datasheet formula. */ value = offsetReg - 32768; /* Send the requested value to user */ CONSOLE_Print("%s%d [LSBs]\r\n", cmdList[6].name, value); }
/***************************************************************************//** * @brief Displays last gain value from the Gain Adjust register. * * @return None. *******************************************************************************/ void GetGain(double* param, char paramNo) // "gain?" command { int value = 0; gainReg = AD5421_GetGain(); /* Calculate according to the datasheet formula. */ value = gainReg - 65535; /* Send the requested value to user */ CONSOLE_Print("%s%d [LSBs]\r\n", cmdList[8].name, value); }
/***************************************************************************//** * @brief Initializes the device. * * @return - The result of the initialization. * Example: ERROR - the device was not initialized or the device * is not present. * SUCCES - the device was initialized and the device * is present. *******************************************************************************/ char DoDeviceInit(void) { if(AD5781_Init() == 0) { CONSOLE_Print("AD5781 OK\r\n"); GetHelp(NULL, 0); registerValue = (AD5781_GetRegisterValue(AD5781_REG_DAC) & ~(AD5781_ADDR_REG(-1))) >> 2; return SUCCESS; }
void CConfig :: Read( string file ) { ifstream in; in.open( file.c_str( ) ); if( in.fail( ) ) CONSOLE_Print( "[CONFIG] warning - unable to read file [" + file + "]" ); else { CONSOLE_Print( "[CONFIG] loading file [" + file + "]" ); string Line; while( !in.eof( ) ) { getline( in, Line ); // ignore blank lines and comments if( Line.empty( ) || Line[0] == '#' ) continue; // remove newlines and partial newlines to help fix issues with Windows formatted config files on Linux systems Line.erase( remove( Line.begin( ), Line.end( ), '\r' ), Line.end( ) ); Line.erase( remove( Line.begin( ), Line.end( ), '\n' ), Line.end( ) ); string :: size_type Split = Line.find( "=" ); if( Split == string :: npos ) continue; string :: size_type KeyStart = Line.find_first_not_of( " " ); string :: size_type KeyEnd = Line.find( " ", KeyStart ); string :: size_type ValueStart = Line.find_first_not_of( " ", Split + 1 ); string :: size_type ValueEnd = Line.size( ); if( ValueStart != string :: npos ) m_CFG[Line.substr( KeyStart, KeyEnd - KeyStart )] = Line.substr( ValueStart, ValueEnd - ValueStart ); } in.close( ); } }
bool CTCPServer :: Listen( string address, uint16_t port ) { if( m_Socket == INVALID_SOCKET || m_HasError ) return false; m_SIN.sin_family = AF_INET; if( !address.empty( ) ) { if( ( m_SIN.sin_addr.s_addr = inet_addr( address.c_str( ) ) ) == INADDR_NONE ) m_SIN.sin_addr.s_addr = INADDR_ANY; } else m_SIN.sin_addr.s_addr = INADDR_ANY; m_SIN.sin_port = htons( port ); if( ::bind( m_Socket, (struct sockaddr *)&m_SIN, sizeof( m_SIN ) ) == SOCKET_ERROR ) { m_HasError = true; m_Error = GetLastError( ); if (m_isConsolePrint) CONSOLE_Print( "[TCPSERVER] error (bind) - " + GetErrorString( ) ); return false; } // listen, queue length 8 if( listen( m_Socket, 8 ) == SOCKET_ERROR ) { m_HasError = true; m_Error = GetLastError( ); if (m_isConsolePrint) CONSOLE_Print( "[TCPSERVER] error (listen) - " + GetErrorString( ) ); return false; } return true; }
void CGamePlayer :: PushCMDMessage( string message, bool check ) { if( m_LastCMDMessages.size( ) >= 8) m_LastCMDMessages.pop_front( ); m_LastCMDMessages.push_back(message); if( m_LastCMDMessages.size( ) == 7 ) if(!check){ m_Game->SendAllChat( m_Game->m_GHost->m_Language->KickMsgForAbuser( GetName( ) ) ); CONSOLE_Print("[" + m_Game->GetGameName( )+ "] Player "+GetName()+" appears to be a command abuser!"); } }
void CRemoteConsole :: PluginLoaded( CGHost *ghost, CConfig *cfg ) { m_GHost = ghost; QString bindto = cfg->GetString( "rcon_bindto", "255.255.255.255" ); qint32 port = cfg->GetInt( "rcon_port", 6969 ); m_Password = cfg->GetString( "rcon_password", "lol" ); m_Timeout = cfg->GetInt( "rcon_timeout", 10 ); m_KeepAliveTime = cfg->GetInt( "rcon_keepalivetime", 120 ); m_KeepAliveInterval = cfg->GetInt( "rcon_keepaliveinterval", 2 ); m_AnonymousBroadcast = cfg->GetInt( "rcon_anonymousbroadcast", 0 ) == 0 ? false : true; m_AnonymousAdminGame = cfg->GetInt( "rcon_anonymousadmingame", 0 ) == 0 ? false : true; QHostAddress bindAddr( bindto ); if( m_Password.isEmpty( ) ) { bindAddr = QHostAddress::LocalHost; CONSOLE_Print("[RCON] WARNING: No rcon_password set in the .cfg file! Only local commands allowed!"); } // we are all set, lets create our socket // TODO: bind correctly if( !m_UDPSocket->bind( bindAddr, port ) ) { CONSOLE_Print( "[RCON] ERROR: Could not bind to [" + bindto + "] on port [" + QString :: number( port ) + "]" ); } else { CONSOLE_Print( "[RCON] Listening at [" + bindto + "] on port [" + QString :: number( port ) + "]" ); //disabled for now /*if( m_AnonymousBroadcast ) CONSOLE_Print( "[RCON] Anonymous broadcasting [enabled]" ); else CONSOLE_Print( "[RCON] Anonymous broadcasting [disabled]" ); if( m_AnonymousAdminGame ) CONSOLE_Print( "[RCON] Anonymous Admin game [enabled]" ); else CONSOLE_Print( "[RCON] Anonymous Admin game [disabled]" );*/ } }
CRemoteConsole :: CRemoteConsole( CGHost *ghost, CConfig *cfg ) : m_GHost( ghost ) { CONSOLE_Print( "[RCON] Console version 1.4 starting up" ); // lookup "localhost" for later use //bool lookup_success = (inet_aton("localhost", &localhost) == 1); bool lookup_success = true; localhost.s_addr = htonl( INADDR_LOOPBACK ); string bindto = cfg->GetString( "rcon_bindto", "255.255.255.255" ); int port = cfg->GetInt( "rcon_port", 6969 ); m_Password = cfg->GetString( "rcon_password", string( ) ); m_Timeout = cfg->GetInt( "rcon_timeout", 10 ); m_KeepAliveTime = cfg->GetInt( "rcon_keepalivetime", 120 ); m_KeepAliveInterval = cfg->GetInt( "rcon_keepaliveinterval", 2 ); m_AnonymousBroadcast = cfg->GetInt( "rcon_anonymousbroadcast", 0 ) == 0 ? false : true; m_AnonymousAdminGame = cfg->GetInt( "rcon_anonymousadmingame", 0 ) == 0 ? false : true; if ( !m_Password.empty( ) || lookup_success) { if( m_Password.empty( ) ) CONSOLE_Print("[RCON] WARNING: No rcon_password set in the .cfg file! Only local commands allowed!"); // we are all set, lets create our socket m_Socket = new CUDPServer( ); if ( !m_Socket->Bind( bindto, port ) ) { CONSOLE_Print( "[RCON] ERROR: Could not bind to [" + bindto + "] on port [" + UTIL_ToString( port ) + "]" ); delete m_Socket; m_Socket = NULL; } else { CONSOLE_Print( "[RCON] Listening at [" + bindto + "] on port [" + UTIL_ToString( port ) + "]" ); //disabled for now if( m_AnonymousBroadcast ) CONSOLE_Print( "[RCON] Anonymous broadcasting [enabled]" ); else CONSOLE_Print( "[RCON] Anonymous broadcasting [disabled]" ); if( m_AnonymousAdminGame ) CONSOLE_Print( "[RCON] Anonymous Admin game [enabled]" ); else CONSOLE_Print( "[RCON] Anonymous Admin game [disabled]" ); } } else CONSOLE_Print("[RCON] ERROR: No rcon_password set in the .cfg file and lookup failed! RCON disabled!"); }
void CSocket :: Allocate( int type ) { m_Socket = socket( AF_INET, type, 0 ); if( m_Socket == INVALID_SOCKET ) { m_HasError = true; m_Error = GetLastError( ); CONSOLE_Print( "[SOCKET] error (socket) - " + GetErrorString( ) ); return; } }
/***************************************************************************//** * @brief Sets the output resistance between W and B, in ohms. * * @return None. *******************************************************************************/ void SetResistance(double* param, char paramNo) /*!< "resistance=" command */ { double tempFloat = 0; /*!< Check if the parameter is valid */ if(paramNo >= 1) { if(param[0] < 60) { param[0] = 60; } if(param[0] > 10020) { param[0] = 10020; } outResistance = param[0]; /*!< Find the binary value corresponding to the output voltage*/ tempFloat = ((outResistance - R_W) / (double)R_AB) * 256; registerValue = (unsigned char)tempFloat; /*!< Round the value */ if(tempFloat - registerValue >= 0.5) { registerValue ++; } /*!< Write to DAC register */ AD5160_Set(registerValue); /*!< Send feedback to user */ outResistance = R_AB * ((double)registerValue / 256) + R_W; /*!< Convert float to string and send it to user */ CONSOLE_Print("%s%d [ohms]\r\n",(char*)cmdList[1],\ (unsigned short)outResistance); } else { /*!< Display error messages */ CONSOLE_Print("Invalid parameter!\r\n"); CONSOLE_Print("%s%s\r\n", (char*)cmdList[1], (char*)cmdDescription[1]); CONSOLE_Print("Example: %s\r\n", (char*)cmdExample[1]); } }
CLanguage :: CLanguage( string nCFGFile ) { m_CFG = new CConfig( ); m_CFG->Read( nCFGFile ); ifstream in; in.open( "jokes.txt" ); if( in.fail( ) ) CONSOLE_Print( "[JOKES] error loading jokes from [jokes.txt]" ); else { CONSOLE_Print( "[JOKES] loading jokes from [jokes.txt]" ); m_Jokes.clear(); string Line; while( !in.eof( ) ) { getline( in, Line ); // ignore blank lines and comments if( Line.empty( ) || Line[0] == '#' ) continue; // remove newlines and partial newlines to help fix issues with Windows formatted files on Linux systems //Line.erase( remove( Line.begin( ), Line.end( ), ' ' ), Line.end( ) ); Line.erase( remove( Line.begin( ), Line.end( ), '\r' ), Line.end( ) ); Line.erase( remove( Line.begin( ), Line.end( ), '\n' ), Line.end( ) ); m_Jokes.push_back( Line ); } in.close( ); CONSOLE_Print( "[JOKES] loaded " + UTIL_ToString( m_Jokes.size( ) ) + " jokes." ); } }
/***************************************************************************//** * @brief Sets the output current. * * @param param[0] - desired value to be set in milliamps. * * @return None. *******************************************************************************/ void SetCurrent(double* param, char paramNo) // "current=" command { float floatValue = 0; /* Check if the parameter is valid */ if(paramNo >= 1) { if(param[0] < 4) { param[0] = 4; } if(param[0] > 20) { param[0] = 20; } /* Datasheet formula */ floatValue = ((float)param[0] - (4 + (16 * ((float)offsetReg - 32768)) / 65536)) * 65536 * 65536 / (16 * (float)gainReg); /* Verify the limits of the value to be written in DAC register */ if (floatValue > 65535) { floatValue = 65535; } else if (floatValue < 0) { floatValue = 0; } dacReg = (int)floatValue; /* Write to DAC register */ AD5421_SetDac(dacReg); /* Datasheet formula */ floatValue = (16 * ((float)gainReg / 65536) * ((float)dacReg / 65536)) + 4 + (16 * ((float)offsetReg - 32768) / 65536); /* Establish the current limits in software, in hardware is already done */ if (floatValue < 4) { floatValue = 4; } else if (floatValue > 20) { floatValue = 20; } /* Send the requested value to user */ CONSOLE_Print("%s%.3f [mA]\r\n", cmdList[2].name, floatValue); } else { /* Display error messages */ DisplayError(2); } }
CGHostDBMySQL :: CGHostDBMySQL( CConfig *CFG ) : CGHostDB( CFG ) { m_Server = CFG->GetString( "db_mysql_server", string( ) ); m_Database = CFG->GetString( "db_mysql_database", "ghost" ); m_User = CFG->GetString( "db_mysql_user", string( ) ); m_Password = CFG->GetString( "db_mysql_password", string( ) ); m_Port = CFG->GetInt( "db_mysql_port", 0 ); m_BotID = CFG->GetInt( "db_mysql_botid", 0 ); m_NumConnections = 1; m_OutstandingCallables = 0; mysql_library_init( 0, NULL, NULL ); // create the first connection CONSOLE_Print( "[MYSQL] connecting to database server" ); MYSQL *Connection = NULL; if( !( Connection = mysql_init( NULL ) ) ) { CONSOLE_Print( string( "[MYSQL] " ) + mysql_error( Connection ) ); m_HasError = true; m_Error = "error initializing MySQL connection"; return; } my_bool Reconnect = true; mysql_options( Connection, MYSQL_OPT_RECONNECT, &Reconnect ); if( !( mysql_real_connect( Connection, m_Server.c_str( ), m_User.c_str( ), m_Password.c_str( ), m_Database.c_str( ), m_Port, NULL, 0 ) ) ) { CONSOLE_Print( string( "[MYSQL] " ) + mysql_error( Connection ) ); m_HasError = true; m_Error = "error connecting to MySQL server"; return; } m_IdleConnections.push( Connection ); }
void CGHostDB :: CreateThreadReal( CBaseCallable *callable ) { try { boost :: thread Thread( boost :: ref( *callable ) ); } catch( boost :: thread_resource_error tre ) { CONSOLE_Print( "[GHOST] error spawning thread on attempt #1 [" + string( tre.what( ) ) + "], pausing execution and trying again in 50ms" ); // MILLISLEEP( 50 ); try { boost :: thread Thread( boost :: ref( *callable ) ); } catch( boost :: thread_resource_error tre2 ) { CONSOLE_Print( "[GHOST] error spawning thread on attempt #2 [" + string( tre2.what( ) ) + "], giving up" ); callable->SetReady( true ); } } }
/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ int main(void) { char receivedCmd[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; unsigned char cmd = 0; double param[5] = {0, 0, 0, 0, 0}; char paramNo = 0; char cmdType = -1; char invalidCmd = 0; /*!< Select and initialize the platform. */ if (PLATFORM_Init(XILINX_KC705) < 0) { return -1; } /*!< Initialize the console with selected baud rate for the platform used. */ CONSOLE_Init(UART_BAUDRATE); /*!< Initialize the device. */ DoDeviceInit(); while(1) { /*!< Read the command entered by user through console. */ CONSOLE_GetCommand(receivedCmd); invalidCmd = 0; for(cmd = 0; cmd < cmdNo; cmd++) { paramNo = 0; cmdType = CONSOLE_CheckCommands(receivedCmd, cmdList[cmd].name, \ param, ¶mNo); if(cmdType == UNKNOWN_CMD) { invalidCmd++; } else { cmdFunctions[cmd](param, paramNo); } } /*!< Send feedback to user, if the command entered by user is not a valid one. */ if(invalidCmd == cmdNo) { CONSOLE_Print("Invalid command!\r\n"); } } return 0; }
void CPotentialPlayer :: ProcessPackets( ) { if( !m_Socket ) return; // process all the received packets in the m_Packets queue while( !m_Packets.empty( ) ) { CCommandPacket *Packet = m_Packets.front( ); m_Packets.pop( ); if( Packet->GetPacketType( ) == W3GS_HEADER_CONSTANT ) { // the only packet we care about as a potential player is W3GS_REQJOIN, ignore everything else switch( Packet->GetID( ) ) { case CGameProtocol :: W3GS_REQJOIN: delete m_IncomingJoinPlayer; m_IncomingJoinPlayer = m_Protocol->RECEIVE_W3GS_REQJOIN( Packet->GetData( ) ); if( m_IncomingJoinPlayer && !m_Banned ) m_Game->EventPlayerJoined( this, m_IncomingJoinPlayer ); // don't continue looping because there may be more packets waiting and this parent class doesn't handle them // EventPlayerJoined creates the new player, NULLs the socket, and sets the delete flag on this object so it'll be deleted shortly // any unprocessed packets will be copied to the new CGamePlayer in the constructor or discarded if we get deleted because the game is full delete Packet; return; } } else if( Packet->GetPacketType( ) == GCBI_HEADER_CONSTANT ) { // if( Packet->GetID( ) == CGCBIProtocol :: GCBI_INIT && m_Game->m_GHost->IsLocal( GetExternalIPString( ) ) ) if( Packet->GetID( ) == CGCBIProtocol :: GCBI_INIT ) { delete m_IncomingGarenaUser; m_IncomingGarenaUser = m_Game->m_GHost->m_GCBIProtocol->RECEIVE_GCBI_INIT( Packet->GetData( ) ); string RoomID = UTIL_ToString(m_IncomingGarenaUser->GetRoomID( )); m_RoomName = m_Game->m_GHost->GetRoomName( string( RoomID.begin( ), RoomID.end( ) ) ); CONSOLE_Print( "[GCBI] Garena user detected; userid=" + UTIL_ToString( m_IncomingGarenaUser->GetUserID( ) ) + ", roomid=" + RoomID + ", RoomName=" + m_RoomName + ", experience=" + UTIL_ToString( m_IncomingGarenaUser->GetUserExp( ) ) + ", country=" + m_IncomingGarenaUser->GetCountryCode( ) ); } } delete Packet; } }
void SignalCatcher( int signal ) { CONSOLE_Print( "[!!!] caught signal, shutting down" ); if( gCCBot ) { if( gCCBot->m_Exiting ) exit( 1 ); else gCCBot->m_Exiting = true; } else exit( 1 ); }
void CTCPSocket :: DoRecv( fd_set *fd ) { if( m_Socket == INVALID_SOCKET || m_HasError || !m_Connected ) return; if( FD_ISSET( m_Socket, fd ) ) { // data is waiting, receive it char buffer[1024]; int c = recv( m_Socket, buffer, 1024, 0 ); if( c == SOCKET_ERROR && GetLastError( ) != EWOULDBLOCK ) { // receive error m_HasError = true; m_Error = GetLastError( ); CONSOLE_Print( "[TCPSOCKET] error (recv) - " + GetErrorString( ) ); return; } else if( c == 0 ) { // the other end closed the connection CONSOLE_Print( "[TCPSOCKET] closed by remote host" ); m_Connected = false; } else if( c > 0 ) { // success! add the received data to the buffer m_RecvBuffer += string( buffer, c ); m_LastRecv = GetTime( ); } } }
CStatsDOTA :: CStatsDOTA( CBaseGame *nGame, string nConditions, string nSaveType ) : CStats( nGame ), m_SaveType( nSaveType ), m_Winner( 0 ), m_Min( 0 ), m_Sec( 0 ), m_TowerLimit( false ), m_KillLimit( 0 ), m_TimeLimit( 0 ), m_SentinelTowers( 0 ), m_ScourgeTowers( 0 ), m_SentinelKills( 0 ), m_ScourgeKills( 0 ), m_LastCreepTime( 0 ) { CONSOLE_Print( "[STATSDOTA] using dota stats" ); for( unsigned int i = 0; i < 12; ++i ) m_Players[i] = NULL; // process the win conditions if( !nConditions.empty( ) ) { stringstream SS; SS << nConditions; while( !SS.eof( ) ) { string Condition; SS >> Condition; if( SS.fail( ) ) { CONSOLE_Print( "[STATSDOTA] failed to process win conditions: " + nConditions ); break; } else if( Condition.length( ) >= 2 ) { string Key = Condition.substr( 0, 2 ); string Value = Condition.substr( 2 ); if( Key == "tw" ) m_TowerLimit = UTIL_ToUInt32( Value ); else if( Key == "ki" ) m_KillLimit = UTIL_ToUInt32( Value ); else if( Key == "tm" ) m_TimeLimit = UTIL_ToUInt32( Value ); } } }
void CUDPServer :: RecvFrom( fd_set *fd, struct sockaddr_in *sin, string *message ) { if( m_Socket == INVALID_SOCKET || m_HasError || !sin || !message ){ return; } int AddrLen = sizeof( *sin ); if( FD_ISSET( m_Socket, fd ) ) { // data is waiting, receive it CONSOLE_Print( "DEBUUUUUUUUUUUUUUUUUUUUUG" ); char buffer[1024]; #ifdef WIN32 int c = recvfrom( m_Socket, buffer, 1024, 0, (struct sockaddr *)sin, &AddrLen ); #else int c = recvfrom( m_Socket, buffer, 1024, 0, (struct sockaddr *)sin, (socklen_t *)&AddrLen ); #endif if( c == SOCKET_ERROR && GetLastError( ) != EWOULDBLOCK ) { // receive error m_HasError = true; m_Error = GetLastError( ); CONSOLE_Print( "[UDPSERVER] error (recvfrom) - " + GetErrorString( ) ); } else if( c > 0 ) { // success! *message = string( buffer, c ); } } }
/***************************************************************************//** * @brief Displays the temperature. * * @return None. *******************************************************************************/ void GetTemperature(double* param, char paramNo) /*!< "temperature?" command */ { if(currentMode != 3) { /*!< Read the temperature value from the device */ temperature = ADT7420_GetTemperature(); /*!< Send the requested value to user */ CONSOLE_Print("temperature=%.3f [C]\r\n",temperature); } else { CONSOLE_Print("Device in shutdown mode. Please change the \ mode in order to display the temperature. \r\n"); } }
void CGamePlayer :: Send( BYTEARRAY data ) { // must start counting packet total from beginning of connection // but we can avoid buffering packets until we know the client is using GProxy++ since that'll be determined before the game starts // this prevents us from buffering packets for non-GProxy++ clients m_TotalPacketsSent++; if( m_GProxy && m_Game->GetGameLoaded( ) ){ if( m_GProxyBuffer.size( ) <= 2000 ) m_GProxyBuffer.push( data ); else CONSOLE_Print( "[DENY] Warning: discarding GProxy++ packet from player [" + m_Name + "] due to large queue size (> 2000)" ); } CPotentialPlayer :: Send( data ); }
void CUDPSocket :: SetBroadcastTarget( string subnet ) { if( subnet.empty( ) ) { CONSOLE_Print( "[UDPSOCKET] using default broadcast target" ); m_BroadcastTarget.s_addr = INADDR_BROADCAST; } else { // this function does not check whether the given subnet is a valid subnet the user is on // convert string representation of ip/subnet to in_addr CONSOLE_Print( "[UDPSOCKET] using broadcast target [" + subnet + "]" ); m_BroadcastTarget.s_addr = inet_addr( subnet.c_str( ) ); // if conversion fails, inet_addr( ) returns INADDR_NONE if( m_BroadcastTarget.s_addr == INADDR_NONE ) { CONSOLE_Print( "[UDPSOCKET] invalid broadcast target, using default broadcast target" ); m_BroadcastTarget.s_addr = INADDR_BROADCAST; } } }