PyResult Command_online(Client *who, CommandDB *db, PyServiceMgr *services, const Seperator &args) { if( args.argCount() == 2 ) { if( strcmp("me", args.arg( 1 ).c_str())!=0 ) if( !args.isNumber( 1 ) ) throw PyException( MakeCustomError( "Argument 1 should be an entity ID or me (me=self)" ) ); uint32 entity = atoi( args.arg( 1 ).c_str() ); Client* tgt; if( strcmp("me", args.arg( 1 ).c_str())==0 ) tgt = who; else { tgt = services->entity_list.FindCharacter( entity ); if( NULL == tgt ) throw PyException( MakeCustomError( "Unable to find character %u", entity ) ); } if( !tgt->InPod() ) tgt->GetShip()->OnlineAll(); else throw PyException( MakeCustomError( "Command failed: You can't activate mModulesMgr while in pod")); return(new PyString("All mModulesMgr have been put Online")); } else throw PyException( MakeCustomError( "Command failed: You got the arguments all wrong!")); }
void PrintHelp( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 1 == cmd.argCount() ) { sLog.Log( cmdName, "Available commands:" ); for( size_t i = 0; i < EVETOOL_COMMAND_COUNT; ++i ) { const EVEToolCommand* c = &EVETOOL_COMMANDS[i]; sLog.Log( cmdName, "%s", c->name ); } sLog.Log( cmdName, "You can get detailed help by typing '%s <command> [<command>] ...'.", cmdName ); } else { for( size_t i = 1; i < cmd.argCount(); ++i ) { const std::string& cmdStr = cmd.arg( i ); const EVEToolCommand* c = FindCommand( cmdStr ); if( NULL == c ) sLog.Error( cmdName, "Unknown command '%s'.", cmdStr.c_str() ); else sLog.Log( cmdName, "%s: %s", c->name, c->description ); } } }
PyResult Command_setattr( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() < 4 ) { throw PyException( MakeCustomError("Correct Usage: /setattr [itemID] [attributeID] [value]") ); } if( !args.isNumber( 1 ) ) throw PyException( MakeCustomError( "1st argument must be itemID (got %s).", args.arg( 1 ).c_str() ) ); const uint32 itemID = atoi( args.arg( 1 ).c_str() ); if( !args.isNumber( 2 ) ) throw PyException( MakeCustomError( "2nd argument must be attributeID (got %s).", args.arg( 2 ).c_str() ) ); const ItemAttributeMgr::Attr attribute = (ItemAttributeMgr::Attr)atoi( args.arg( 2 ).c_str() ); if( !args.isNumber( 3 ) ) throw PyException( MakeCustomError( "3rd argument must be value (got %s).", args.arg( 3 ).c_str() ) ); const double value = atof( args.arg( 3 ).c_str() ); InventoryItemRef item = services->item_factory.GetItem( itemID ); if( !item ) throw PyException( MakeCustomError( "Failed to load item %u.", itemID ) ); //item->attributes.SetReal( attribute, value ); sLog.Warning( "GMCommands: Command_dogma()", "This command will modify attribute and send change to client, but change does not take effect in client for some reason." ); item->SetAttribute(attribute, (float)value); return new PyString( "Operation successful." ); }
PyResult Command_tr( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() < 3 ) { throw PyException( MakeCustomError("Correct Usage: /tr [entityID]") ); } const std::string& name = args.arg( 1 ); if( "me" != name ) throw PyException( MakeCustomError( "Translocate (/TR) to non-me who '%s' is not supported yet.", name.c_str() ) ); if( !args.isNumber( 2 ) ) throw PyException( MakeCustomError( "Argument 1 should be an entity ID" ) ); uint32 loc = atoi( args.arg( 2 ).c_str() ); sLog.Log( "Command", "Translocate to %u.", loc ); GPoint p( 0.0f, 1000000.0f, 0.0f ); //when going to a system, who knows where to stick them... could find a stargate and stick them near it I guess... if( !IsStation( loc ) && !IsSolarSystem( loc ) ) { Client* target = services->entity_list.FindCharacter( loc ); if( NULL == target ) target = services->entity_list.FindByShip( loc ); if( NULL == target ) throw PyException( MakeCustomError( "Unable to find location %u.", loc ) ); loc = target->GetLocationID(); p = target->GetPosition(); } who->MoveToLocation( loc , p ); return new PyString( "Translocation successful." ); }
PyResult Command_giveisk( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() < 3 ) { throw PyException( MakeCustomError("Correct Usage: /giveisk [entityID (0=self)] [amount]") ); } if( !args.isNumber( 1 ) ) throw PyException( MakeCustomError( "Argument 1 should be an entity ID (0=self)" ) ); uint32 entity = atoi( args.arg( 1 ).c_str() ); if( !args.isNumber( 2 ) ) throw PyException( MakeCustomError( "Argument 2 should be an amount of ISK" ) ); double amount = strtod( args.arg( 2 ).c_str(), NULL ); Client* tgt; if( 0 == entity ) tgt = who; else { tgt = services->entity_list.FindCharacter( entity ); if( NULL == tgt ) throw PyException( MakeCustomError( "Unable to find character %u", entity ) ); } tgt->AddBalance( amount ); return new PyString( "Operation successful." ); }
void TriToOBJ( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 4 != cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s [trifile] [objout] [mtlout]", cmdName ); return; } const std::string& trifile = cmd.arg( 1 ); const std::string& objout = cmd.arg( 2 ); const std::string& mtlout = cmd.arg( 3 ); TriExporter::TriFile f; if( !f.LoadFile( trifile.c_str() ) ) { sLog.Error( cmdName, "Failed to load trifile '%s'.", trifile.c_str() ); return; } f.DumpHeaders(); f.ExportObj( objout.c_str(), mtlout.c_str() ); sLog.Success( cmdName, "%s - %s - written.", objout.c_str(), mtlout.c_str() ); }
void UnmarshalLogText( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 1 == cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s marshal-binary [marshal-binary] ...", cmdName ); return; } for( size_t i = 1; i < cmd.argCount(); ++i ) { const std::string& marshalBinaryStr = cmd.arg( i ); Buffer marshalBinary; if( !PyDecodeEscape( marshalBinaryStr.c_str(), marshalBinary ) ) { sLog.Error( cmdName, "Failed to decode string into binary." ); continue; } PyRep* r = InflateUnmarshal( marshalBinary ); if( NULL == r ) sLog.Error( cmdName, "Failed to unmarshal binary." ); else { sLog.Success( cmdName, "Result:" ); r->Dump( stdout, " " ); PyDecRef( r ); } } }
PyResult Command_heal( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount()== 1 ) { /*who->GetShip()->Set_armorDamage(0); who->GetShip()->Set_damage(0); who->GetShip()->Set_shieldCharge(who->GetShip()->shieldCapacity());*/ who->GetShip()->SetAttribute(AttrArmorDamage, 0); who->GetShip()->SetAttribute(AttrDamage, 0); EvilNumber shield_charge = who->GetShip()->GetAttribute(AttrShieldCapacity); who->GetShip()->SetAttribute(AttrShieldCharge, shield_charge); } if( args.argCount() == 2 ) { if( !args.isNumber( 1 ) ) { throw PyException( MakeCustomError( "Argument 1 should be a character ID" ) ); } uint32 entity = atoi( args.arg( 1 ).c_str() ); Client *target = services->entity_list.FindCharacter( entity ); if(target == NULL) throw PyException( MakeCustomError( "Cannot find Character by the entity %d", entity ) ); who->GetShip()->SetAttribute(AttrArmorDamage, 0); who->GetShip()->SetAttribute(AttrDamage, 0); EvilNumber shield_charge = who->GetShip()->GetAttribute(AttrShieldCapacity); who->GetShip()->SetAttribute(AttrShieldCharge, shield_charge); } return(new PyString("Heal successful!")); }
PyResult Command_roid( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( !args.isNumber( 1 ) ) throw PyException( MakeCustomError( "Argument 1 should be an item type ID" ) ); const uint32 typeID = atoi( args.arg( 1 ).c_str() ); if( !args.isNumber( 2 ) ) throw PyException( MakeCustomError( "Argument 2 should be a radius" ) ); const double radius = atof( args.arg( 2 ).c_str() ); if( 0 >= radius ) throw PyException( MakeCustomError( "Invalid radius." ) ); if( !who->IsInSpace() ) throw PyException( MakeCustomError( "You must be in space to spawn things." ) ); sLog.Log( "Command", "Roid %u of radius %f", typeID, radius ); GPoint position( who->GetPosition() ); position.x += radius + 1 + who->GetRadius(); //put it raw enough away to not push us around. SpawnAsteroid( who->System(), typeID, radius, position ); return new PyString( "Spawn successsfull." ); }
void ObjectToSQL( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 5 != cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s [cache_file] [table_name] [key_field] [file_name]", cmdName ); return; } const std::string& cacheFile = cmd.arg( 1 ); const std::string& tableName = cmd.arg( 2 ); const std::string& keyField = cmd.arg( 3 ); const std::string& fileName = cmd.arg( 4 ); std::string abs_fname( "../data/cache/" ); abs_fname += cacheFile; abs_fname += ".cache"; sLog.Log( cmdName, "Converting cached object %s:\n", abs_fname.c_str() ); CachedObjectMgr mgr; PyCachedObjectDecoder* obj = mgr.LoadCachedObject( abs_fname.c_str(), cacheFile.c_str() ); if( obj == NULL ) { sLog.Error( cmdName, "Unable to load or decode '%s'!", abs_fname.c_str() ); return; } obj->cache->DecodeData(); if( obj->cache->decoded() == NULL ) { sLog.Error( cmdName, "Unable to load or decode body of '%s'!", abs_fname.c_str() ); SafeDelete( obj ); return; } FILE* out = fopen( fileName.c_str(), "w" ); if( out == NULL ) { sLog.Error( cmdName, "Unable to open output file '%s'", fileName.c_str() ); SafeDelete( obj ); return; } SetSQLDumper dumper( tableName.c_str(), keyField.c_str(), out ); if( obj->cache->decoded()->visit( dumper ) ) sLog.Success( cmdName, "Dumping of %s succeeded.", tableName.c_str() ); else sLog.Error( cmdName, "Dumping of %s failed.", tableName.c_str() ); fclose( out ); SafeDelete( obj ); }
void LoadScript( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 1 == cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s file [file] ...", cmdName ); return; } for( size_t i = 1; i < cmd.argCount(); ++i ) ProcessFile( cmd.arg( i ) ); }
PyResult Command_unban( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() == 2 ) { if( !args.isNumber( 1 ) ) { const char *name = args.arg( 1 ).c_str(); services->serviceDB().SetAccountBanStatus(db->GetAccountID(name),false); } else throw PyException( MakeCustomError("Correct Usage: /ban [Character Name]") ); } //support for characters with first and last names else if( args.argCount() == 3 ) { if( args.isHexNumber( 1 ) ) throw PyException( MakeCustomError("Unknown arguments") ); std::string name = args.arg( 1 ) + " " + args.arg( 2 ); services->serviceDB().SetAccountBanStatus(db->GetAccountID(name),false); } else throw PyException( MakeCustomError("Correct Usage: /unban [Character Name / Character ID]") ); return NULL; }
PyResult Command_dogma( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { //"dogma" "140019878" "agility" "=" "0.2" if( !(args.argCount() == 5) ) { throw PyException( MakeCustomError("Correct Usage: /dogma [itemID] [attributeName] = [value]") ); } if( !args.isNumber( 1 ) ){ throw PyException( MakeCustomError("Invalid itemID. \n Correct Usage: /dogma [itemID] [attributeName] = [value]") ); } uint32 itemID = atoi( args.arg( 1 ).c_str() ); if( args.isNumber( 2 ) ) { throw PyException( MakeCustomError("Invalid attributeName. \n Correct Usage: /dogma [itemID] [attributeName] = [value]") ); } const char *attributeName = args.arg( 2 ).c_str(); if( !args.isNumber( 4 ) ){ throw PyException( MakeCustomError("Invalid attribute value. \n Correct Usage: /dogma [itemID] [attributeName] = [value]") ); } double attributeValue = atof( args.arg( 4 ).c_str() ); //get item InventoryItemRef item = services->item_factory.GetItem( itemID ); //get attributeID uint32 attributeID = db->GetAttributeID( attributeName ); sLog.Warning( "GMCommands: Command_dogma()", "This command will modify attribute and send change to client, but change does not take effect in client for some reason." ); item->SetAttribute( attributeID, attributeValue ); return NULL; }
PyResult Command_ban( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { Client *target; if( args.argCount() == 2 ) { if( !args.isNumber( 1 ) ) { const char *name = args.arg( 1 ).c_str(); target = services->entity_list.FindCharacter( name ); } else throw PyException( MakeCustomError("Correct Usage: /ban [Character Name]") ); } //support for characters with first and last names else if( args.argCount() == 3 ) { if( args.isHexNumber( 1 ) ) throw PyException( MakeCustomError("Unknown arguments") ); std::string name = args.arg( 1 ) + " " + args.arg( 2 ); target = services->entity_list.FindCharacter( name.c_str() ) ; } else throw PyException( MakeCustomError("Correct Usage: /ban [Character Name]") ); //ban client target->BanClient(); //disconnect client target->DisconnectClient(); return NULL; }
PyResult Command_search( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() < 2 ) { throw PyException( MakeCustomError("Correct Usage: /search [text]") ); } const std::string& query = args.arg( 1 ); //an empty query is a bad idea. if( 0 == query.length() ) throw PyException( MakeCustomError( "Usage: /search [text]" ) ); std::map<uint32, std::string> matches; if( !db->ItemSearch( query.c_str(), matches ) ) throw PyException( MakeCustomError( "Failed to query DB." ) ); std::string result( itoa( matches.size() ) ); result += " matches found.<br>"; std::map<uint32, std::string>::iterator cur, end; cur = matches.begin(); end = matches.end(); for(; cur != end; cur++) { result += itoa( cur->first ); result += ": "; result += cur->second; result += "<br>"; } if( 10 < matches.size() ) { //send the results in an evemail. std::string subject( "Search results for " ); subject += query; who->SelfEveMail( subject.c_str(), result.c_str() ); return new PyString( "Results sent via evemail." ); } else return new PyString( result ); }
void ProcessCommand( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); const EVEToolCommand* c = FindCommand( cmdName ); if( NULL == c ) sLog.Error( "input", "Unknown command '%s'.", cmdName ); else ( *c->callback )( cmd ); }
PyResult Command_createitem( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() < 2 ) { throw PyException( MakeCustomError("Correct Usage: /create [typeID]") ); } //basically, a copy/paste from Command_create. The client seems to call this multiple times, //each time it creates an item if( !args.isNumber( 1 ) ) throw PyException( MakeCustomError( "Argument 1 must be type ID." ) ); const uint32 typeID = atoi( args.arg( 1 ).c_str() ); uint32 qty = 1; if( 2 < args.argCount() ) { if( args.isNumber( 2 ) ) qty = atoi( args.arg( 2 ).c_str() ); } sLog.Log("command message", "Create %s %u times", args.arg( 1 ).c_str(), qty ); //create into their cargo hold unless they are docked in a station, //then stick it in their hangar instead. uint32 locationID; EVEItemFlags flag; if( who->IsInSpace() ) { locationID = who->GetShipID(); flag = flagCargoHold; } else { locationID = who->GetStationID(); flag = flagHangar; } ItemData idata( typeID, who->GetCharacterID(), 0, //temp location flag, qty ); InventoryItemRef i = services->item_factory.SpawnItem( idata ); if( !i ) throw PyException( MakeCustomError( "Unable to create item of type %s.", args.arg( 1 ).c_str() ) ); //Move to location i->Move( locationID, flag, true ); return new PyString( "Creation successful." ); }
PyResult Command_goto( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args) { if( 3 != args.argCount() || !args.isNumber( 1 ) || !args.isNumber( 2 ) || !args.isNumber( 3 ) ) { throw PyException( MakeCustomError( "Correct Usage: /goto [x coord] [y coor] [z coord]" ) ); } GPoint p( atof( args.arg( 1 ).c_str() ), atof( args.arg( 2 ).c_str() ), atof( args.arg( 3 ).c_str() ) ); sLog.Log( "Command", "%s: Goto (%.13f, %.13f, %.13f)", who->GetName(), p.x, p.y, p.z ); who->MoveToPosition( p ); return new PyString( "Goto successful." ); }
void TimeToString( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 1 == cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s win32-time [win32-time] ...", cmdName ); return; } for( size_t i = 1; i < cmd.argCount(); ++i ) { const std::string& timeStr = cmd.arg( i ); uint64 t; sscanf( timeStr.c_str(), I64u, &t ); const std::string time = Win32TimeToString( t ); sLog.Log( cmdName, "%s is %s.", timeStr.c_str(), time.c_str() ); } }
PyResult Command_repairmodules( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if(args.argCount()==1) { who->GetShip()->RepairModules(); } if(args.argCount()==2) { if( !args.isNumber( 1 ) ) { throw PyException( MakeCustomError( "Argument 1 should be a character ID" ) ); } uint32 charID = atoi( args.arg( 1 ).c_str() ); Client *target = services->entity_list.FindCharacter( charID ); if(target == NULL) throw PyException( MakeCustomError( "Cannot find Character by the entity %d", charID ) ); target->GetShip()->RepairModules(); } return(new PyString("Modules repaired successful!")); }
PyResult Command_pop( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( 4 != args.argCount() ) throw PyException( MakeCustomError( "Correct Usage: /pop [message type] [key] [text]" ) ); //CustomNotify: notify //ServerMessage: msg //CustomError: error const std::string& msgType = args.arg( 1 ); const std::string& key = args.arg( 2 ); const std::string& text = args.arg( 3 ); Notify_OnRemoteMessage n; n.msgType = msgType; n.args[ key ] = new PyString( text ); PyTuple* t = n.Encode(); who->SendNotification( "OnRemoteMessage", "charid", &t ); PySafeDecRef( t ); return new PyString( "Message sent." ); }
void TestMarshal( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); DBRowDescriptor *header = new DBRowDescriptor; // Fill header: header->AddColumn( "historyDate", DBTYPE_FILETIME ); header->AddColumn( "lowPrice", DBTYPE_CY ); header->AddColumn( "highPrice", DBTYPE_CY ); header->AddColumn( "avgPrice", DBTYPE_CY ); header->AddColumn( "volume", DBTYPE_I8 ); header->AddColumn( "orders", DBTYPE_I4 ); CRowSet* rs = new CRowSet( &header ); PyPackedRow* row = rs->NewRow(); row->SetField( "historyDate", new PyLong( Win32TimeNow() ) ); row->SetField( "lowPrice", new PyLong( 18000 ) ); row->SetField( "highPrice", new PyLong( 19000 ) ); row->SetField( "avgPrice", new PyLong( 18400 ) ); row->SetField( "volume", new PyLong( 5463586 ) ); row->SetField( "orders", new PyInt( 254 ) ); sLog.Log( cmdName, "Marshaling..." ); Buffer marshaled; bool res = MarshalDeflate( rs, marshaled ); PyDecRef( rs ); if( !res ) { sLog.Error( cmdName, "Failed to marshal Python object." ); return; } sLog.Log( cmdName, "Unmarshaling..." ); PyRep* rep = InflateUnmarshal( marshaled ); if( NULL == rep ) { sLog.Error( cmdName, "Failed to unmarshal Python object." ); return; } sLog.Success( cmdName, "Final:" ); rep->Dump( stdout, " " ); PyDecRef( rep ); }
void DestinyDumpLogText( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 1 == cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s destiny-binary [destiny-binary] ...", cmdName ); return; } for( size_t i = 1; i < cmd.argCount(); ++i ) { const std::string& destinyBinaryStr = cmd.arg( i ); Buffer destinyBinary; if( !PyDecodeEscape( destinyBinaryStr.c_str(), destinyBinary ) ) { sLog.Error( cmdName, "Failed to decode destiny binary." ); continue; } Destiny::DumpUpdate( DESTINY__MESSAGE, &destinyBinary[0], destinyBinary.size() ); } }
PyResult Command_kenny( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() == 2 ) { if( args.arg(1) == "ON" || args.arg(1) == "On" || args.arg(1) == "oN" || args.arg(1) == "on" || args.arg(1) == "1" ) { // Enable Kenny Translator who->EnableKennyTranslator(); } else if( args.arg(1) == "OFF" || args.arg(1) == "off" || args.arg(1) == "Off" || args.arg(1) == "0" ) { // Disable Kenny Translator who->DisableKennyTranslator(); } else throw PyException( MakeCustomError("Correct Usage: /kenny ON/OFF On/Off on/off 1/0") ); } else throw PyException( MakeCustomError("Correct Usage: /kenny ON/OFF On/Off on/off 1/0") ); return NULL; }
PyResult Command_getattr( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( args.argCount() < 3 ) { throw PyException( MakeCustomError("Correct Usage: /getattr [itemID] [attributeID]") ); } if( !args.isNumber( 1 ) ) throw PyException( MakeCustomError( "1st argument must be itemID (got %s).", args.arg( 1 ).c_str() ) ); const uint32 itemID = atoi( args.arg( 1 ).c_str() ); if( !args.isNumber( 2 ) ) throw PyException( MakeCustomError( "2nd argument must be attributeID (got %s).", args.arg( 2 ).c_str() ) ); const ItemAttributeMgr::Attr attribute = (ItemAttributeMgr::Attr)atoi( args.arg( 2 ).c_str() ); InventoryItemRef item = services->item_factory.GetItem( itemID ); if( !item ) throw PyException( MakeCustomError( "Failed to load item %u.", itemID ) ); //return item->attributes.PyGet( attribute ); return item->GetAttribute(attribute).GetPyObject(); }
PyResult Command_unspawn( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { uint32 entityID = 0; uint32 itemID = 0; if( (args.argCount() < 3) || (args.argCount() > 3) ) throw PyException( MakeCustomError("Correct Usage: /unspawn (entityID) (itemID), and for now (entityID) is unused, so just type 0, and use the itemID from the entity table for (itemID)") ); if( !(args.isNumber( 1 )) ) throw PyException( MakeCustomError( "Argument 1 should be an item entity ID" ) ); if( !(args.isNumber( 2 )) ) throw PyException( MakeCustomError( "Argument 2 should be an item item ID" ) ); entityID = atoi( args.arg( 1 ).c_str() ); itemID = atoi( args.arg( 2 ).c_str() ); if( !who->IsInSpace() ) throw PyException( MakeCustomError( "You must be in space to unspawn things." ) ); // Search for the itemRef for itemID: InventoryItemRef itemRef = who->services().item_factory.GetItem( itemID ); SystemEntity * entityRef = who->System()->get( itemID ); // Actually do the unspawn using SystemManager's RemoveEntity: if( entityRef == NULL ) { return new PyString( "Un-Spawn Failed: itemID not found." ); } else { who->System()->RemoveEntity( entityRef ); itemRef->Delete(); } sLog.Log( "Command", "%s: Un-Spawned %u.", who->GetName(), itemID ); return new PyString( "Un-Spawn successful." ); }
PyResult Command_unload(Client *who, CommandDB *db, PyServiceMgr *services, const Seperator &args) { if( args.argCount() >= 2 && args.argCount() <= 3 ) { uint32 item=0,entity=0; if( strcmp("me", args.arg( 1 ).c_str())!=0 ) if( !args.isNumber( 1 ) ) { throw PyException( MakeCustomError( "Argument 1 should be an entity ID or me (me=self)" ) ); } entity = atoi( args.arg( 1 ).c_str() ); if( args.argCount() ==3 ) { if( strcmp("all", args.arg( 2 ).c_str())!=0 ) if( !args.isNumber( 2 ) ) throw PyException( MakeCustomError( "Argument 2 should be an item ID or all" ) ); item = atoi( args.arg( 2 ).c_str() ); } //select character Client* tgt; if( strcmp("me", args.arg( 1 ).c_str())==0 ) tgt = who; else { tgt = services->entity_list.FindCharacter( entity ); if( NULL == tgt ) throw PyException( MakeCustomError( "Unable to find character %u", entity ) ); } if( tgt->IsInSpace() ) throw PyException( MakeCustomError( "Character needs to be docked!" ) ); if( args.argCount() == 3 && strcmp("all", args.arg( 2 ).c_str())!=0) tgt->GetShip()->UnloadModule(item); if( args.argCount() == 3 && strcmp("all", args.arg( 2 ).c_str())==0) tgt->GetShip()->UnloadAllModules(); return(new PyString("All mModulesMgr have been unloaded")); } else throw PyException( MakeCustomError( "Command failed: You got the arguments all wrong!")); }
void StuffExtract( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 2 != cmd.argCount() ) { sLog.Error( cmdName, "Usage: %s [.stuff file]", cmdName ); return; } const std::string& filename = cmd.arg( 1 ); FILE* in = fopen( filename.c_str(), "rb" ); if( NULL == in ) { sLog.Error( cmdName, "Unable to open %s.", filename.c_str() ); return; } uint32 file_count; if( 1 != fread( &file_count, sizeof( file_count ), 1, in ) ) { sLog.Log( cmdName, "Unable to read file count." ); return; } sLog.Log( cmdName, "There are %u files in %s.", file_count, filename.c_str() ); std::vector<FileHeaderObj> headers; headers.resize( file_count ); size_t offset = 0; for( uint32 i = 0; i < file_count; i++ ) { FileHeader head; if( 1 != fread( &head, sizeof( head ), 1, in ) ) { sLog.Error( cmdName, "Unable to read header of file #%u.", i ); return; } FileHeaderObj& obj = headers[ i ]; obj.length = head.file_size; obj.offset = offset; ++head.path_len; // NULL term //read path name. obj.filename.resize( head.path_len ); if( head.path_len != fread( &obj.filename[0], 1, head.path_len, in ) ) { sLog.Error( cmdName, "Unable to read name of file #%u.", i ); return; } //drop read NULL term obj.filename.resize( head.path_len - 1 ); sLog.Log( cmdName, "File #%u has length %u and path %s.", i, obj.length, obj.filename.c_str() ); offset += head.file_size; } std::vector<FileHeaderObj>::const_iterator cur, end; cur = headers.begin(); end = headers.end(); for(; cur != end; cur++) { //split the path into components, make the intermediate directories //if needed, and then finally open the file and write it out. std::vector<std::string> components; SplitPath( cur->filename, components ); std::string pathname = "."; std::vector<std::string>::const_iterator curc, endc; curc = components.begin(); endc = components.end(); for(; curc != endc; curc++ ) { pathname += "/"; pathname += *curc; if( ( curc + 1 ) == endc ) { //this is the file component. FILE* out = fopen( pathname.c_str(), "wb" ); if( NULL == out ) { sLog.Error( cmdName, "Unable to create file %s: %s.", pathname.c_str(), strerror( errno ) ); break; } sLog.Log( cmdName, "Extracting file %s of length %u.", pathname.c_str(), cur->length ); Buffer buf( cur->length ); if( cur->length != fread( &buf[0], 1, cur->length, in ) ) { sLog.Error( cmdName, "Unable to read file %s: %s.", cur->filename.c_str(), strerror( errno ) ); break; } if( cur->length != fwrite( &buf[0], 1, cur->length, out ) ) { sLog.Error( cmdName, "Unable to write file %s: %s", pathname.c_str(), strerror( errno ) ); break; } fclose( out ); } else { //this is an intermediate directory. struct stat stat_struct; if( -1 == stat( pathname.c_str(), &stat_struct ) ) { if( ENOENT == errno ) { if( -1 == mkdir( pathname.c_str(), ( S_IRWXU | S_IRWXG | S_IRWXO ) ) ) { sLog.Error( cmdName, "Failed to make intermediate directory %s: %s", pathname.c_str(), strerror( errno ) ); break; } } else { sLog.Error( cmdName, "Unable to stat %s: %s", pathname.c_str(), strerror( errno ) ); break; } } } } } fclose( in ); sLog.Log( cmdName, "Extracting from archive %s finished.", filename.c_str() ); }
PyResult Command_spawnbelt( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( !who->IsInSpace() ) throw PyException( MakeCustomError( "You must be in space to spawn things." ) ); bool makeIceBelt = false; bool makeRareIce = false; uint32 customCount = 0; if( args.argCount() >= 2 ) { if( !args.isNumber( 1 ) ) { if( args.arg( 1 ) == "ice" ) makeIceBelt = true; } else { if( atoi(args.arg( 1 ).c_str()) > 15 ) customCount = atoi(args.arg( 1 ).c_str()); else PyException( MakeCustomError( "Argument 1 should be at least 15!" ) ); } } if( args.argCount() >= 3 ) { if( args.isNumber( 2 ) ) { if( atoi(args.arg( 2 ).c_str()) > 15 ) customCount = atoi(args.arg(2).c_str()); else PyException( MakeCustomError( "Argument 2 should be at least 15!" ) ); } else if( args.arg( 2 ) == "ice" ) makeIceBelt = true; if( args.arg( 2 ) == "rareice" ) { makeIceBelt = true; makeRareIce = true; } } const double beltradius = 100000.0; const double beltdistance = 25000.0; double roidradius; const double beltangle = M_PI * 2.0 / 3.0; uint32 pcs = 0; if( customCount > 15 ) pcs = customCount + static_cast<uint32>(MakeRandomInt( -10, 10 )); else pcs = 30 + static_cast<uint32>(MakeRandomInt( -10, 10 )); const GPoint position( who->GetPosition() ); const double R = sqrt( position.x * position.x + position.z * position.z ); const GPoint r = position * ( R + beltdistance - beltradius ) / R; double phi = atan( position.x / position.z ); if( position.z < 0 ) phi += M_PI; SystemManager* sys = who->System(); std::map<double, uint32> roidDist; if( makeIceBelt ) { std::string securityStatus = sys->GetSystemSecurity(); if( !makeRareIce ) { roidDist.insert(std::pair<double,uint32>(0.60,16264)); // Blue Ice roidDist.insert(std::pair<double,uint32>(0.45,17975)); // Thick Blue Ice roidDist.insert(std::pair<double,uint32>(0.30,28627)); // Azure Ice roidDist.insert(std::pair<double,uint32>(0.20,16262)); // Clear Icicle roidDist.insert(std::pair<double,uint32>(0.10,16267)); // Dark Glitter } if( makeRareIce ) { roidDist.insert(std::pair<double,uint32>(0.90,16263)); // Glacial Mass roidDist.insert(std::pair<double,uint32>(0.80,16265)); // White Glaze roidDist.insert(std::pair<double,uint32>(0.70,16266)); // Glare Crust roidDist.insert(std::pair<double,uint32>(0.60,16268)); // Gelidus roidDist.insert(std::pair<double,uint32>(0.50,16269)); // Krystallos roidDist.insert(std::pair<double,uint32>(0.40,17976)); // Pristine White Glaze roidDist.insert(std::pair<double,uint32>(0.30,17977)); // Smooth Glacial Mass roidDist.insert(std::pair<double,uint32>(0.20,17978)); // Enriched Clear Icicle roidDist.insert(std::pair<double,uint32>(0.10,28628)); // Crystalline Icicle } } else { if( !db->GetRoidDist( sys->GetSystemSecurity(), roidDist ) ) { sLog.Error( "Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ); throw PyException( MakeCustomError( "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ) ); } } double distanceToMe; double alpha; GPoint mposition; if( makeIceBelt ) pcs *= 2; for( uint32 i = 0; i < pcs; ++i ) { alpha = beltangle * MakeRandomFloat( -0.5, 0.5 ); if( makeIceBelt ) roidradius = MakeRandomFloat( 1000.0, 10000.0 ); else roidradius = MakeRandomFloat( 100.0, 1000.0 ); mposition.x = beltradius * sin( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 ); mposition.z = beltradius * cos( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 ); mposition.y = position.y - r.y + roidradius * MakeRandomFloat( 0, 15 ); distanceToMe = (r + mposition - position).length(); SpawnAsteroid( who->System(), GetAsteroidType( MakeRandomFloat(), roidDist ), roidradius, r + mposition ); } return new PyString( "Spawn successsfull." ); }
void PrintTimeNow( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); sLog.Log( cmdName, "Now in Win32 time: "I64u".", Win32TimeNow() ); }