From: <ma...@us...> - 2012-04-08 23:17:19
|
Revision: 8197 http://planeshift.svn.sourceforge.net/planeshift/?rev=8197&view=rev Author: magodra Date: 2012-04-08 23:17:13 +0000 (Sun, 08 Apr 2012) Log Message: ----------- - Added /location type add|delete <type> command to add or remove location types. Some work remain on remove. Modified Paths: -------------- trunk/src/common/net/messages.h trunk/src/common/net/npcmessages.cpp trunk/src/common/net/npcmessages.h trunk/src/common/util/location.cpp trunk/src/common/util/location.h trunk/src/npcclient/networkmgr.cpp trunk/src/server/adminmanager.cpp trunk/src/server/database/mysql/sc_npctypes.sql trunk/src/server/npcmanager.cpp trunk/src/server/npcmanager.h Modified: trunk/src/common/net/messages.h =================================================================== --- trunk/src/common/net/messages.h 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/common/net/messages.h 2012-04-08 23:17:13 UTC (rev 8197) @@ -50,7 +50,7 @@ // NPC Networking version is separate so we don't have to break compatibility // with clients to enhance the superclients. Made it a large number to ensure // no inadvertent overlaps. -#define PS_NPCNETVERSION 0x1028 +#define PS_NPCNETVERSION 0x1029 enum Slot_Containers { Modified: trunk/src/common/net/npcmessages.cpp =================================================================== --- trunk/src/common/net/npcmessages.cpp 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/common/net/npcmessages.cpp 2012-04-08 23:17:13 UTC (rev 8197) @@ -1559,6 +1559,37 @@ msg->ClipToCurrentSize(); } +psLocationMessage::psLocationMessage( Command command, const LocationType* locationType ) +{ + msg.AttachNew(new MsgEntry( sizeof(uint8_t) + 1000 , PRIORITY_HIGH )); + msg->clientnum = 0; + msg->SetType(MSGTYPE_LOCATION); + + msg->Add( (uint8_t)command ); + msg->Add( (uint32_t)locationType->GetID() ); + + if (command == LOCATION_TYPE_ADD) + { + msg->Add( locationType->GetName() ); + } +} + +psLocationMessage::psLocationMessage( Command command, const csString& name ) +{ + msg.AttachNew(new MsgEntry( sizeof(uint8_t) + 1000 , PRIORITY_HIGH )); + msg->clientnum = 0; + msg->SetType(MSGTYPE_LOCATION); + + msg->Add( (uint8_t)command ); + msg->Add( (uint32_t)(-1) ); // Read for all messages so we need to set it. + + if (command == LOCATION_TYPE_REMOVE) + { + msg->Add( name ); + } +} + + psLocationMessage::psLocationMessage( MsgEntry* msgEntry ) : id(0), sector(NULL), enable(false), radius(0.0), rotationAngle(0.0) { @@ -1596,6 +1627,12 @@ case LOCATION_RENAME: name = msgEntry->GetStr(); break; + case LOCATION_TYPE_ADD: + typeName = msgEntry->GetStr(); + break; + case LOCATION_TYPE_REMOVE: + typeName = msgEntry->GetStr(); + break; } } @@ -1622,8 +1659,14 @@ str.AppendFmt("Cmd: LOCATION_RADIUS ID: %d Radius: %.2f", id, radius); break; case LOCATION_RENAME: - str.AppendFmt("Cmd: LOCATION_RENAME ID: %d String: %s", id, name.GetDataSafe()); + str.AppendFmt("Cmd: LOCATION_RENAME ID: %d Name: %s", id, name.GetDataSafe()); break; + case LOCATION_TYPE_ADD: + str.AppendFmt("Cmd: LOCATION_TYPE_ADD ID: %d Name: %s", id, typeName.GetDataSafe()); + break; + case LOCATION_TYPE_REMOVE: + str.AppendFmt("Cmd: LOCATION_TYPE_REMOVE ID: %d Name: %s", id, typeName.GetDataSafe()); + break; } return str; Modified: trunk/src/common/net/npcmessages.h =================================================================== --- trunk/src/common/net/npcmessages.h 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/common/net/npcmessages.h 2012-04-08 23:17:13 UTC (rev 8197) @@ -28,6 +28,7 @@ // Forward declarations class Location; +class LocationType; class Waypoint; class WaypointAlias; class psPath; @@ -540,7 +541,9 @@ LOCATION_INSERTED, LOCATION_RADIUS, LOCATION_RENAME, - LOCATION_SET_FLAG + LOCATION_SET_FLAG, + LOCATION_TYPE_ADD, + LOCATION_TYPE_REMOVE } Command; Command command; ///< @@ -561,6 +564,14 @@ */ psLocationMessage(Command command, const Location* location); + /** Generic message to do a command where input is a Location type. + */ + psLocationMessage(Command command, const LocationType* locationType); + + /** Generic message to do a command where input is a string. + */ + psLocationMessage(Command command, const csString& name); + /// Crack incoming psMessageBytes struct for inbound use psLocationMessage(MsgEntry *message); Modified: trunk/src/common/util/location.cpp =================================================================== --- trunk/src/common/util/location.cpp 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/common/util/location.cpp 2012-04-08 23:17:13 UTC (rev 8197) @@ -421,7 +421,17 @@ } /*------------------------------------------------------------------*/ +LocationType::LocationType() + :id(-1) +{ +} +LocationType::LocationType(int id, const csString& name) + :id(id),name(name) +{ +} + + LocationType::~LocationType() { while (locs.GetSize()) @@ -436,7 +446,34 @@ } } +bool LocationType::CreateUpdate(iDataConnection* db) +{ + const char * fields[] = + { + "name"}; + psStringArray values; + values.Push(name); + + if (id == -1) + { + id = db->GenericInsertWithID("sc_location_type",fields,values); + if (id == 0) + { + id = -1; + return false; + } + } + else + { + csString idStr; + idStr.Format("%d",id); + return db->GenericUpdateWithID("sc_location_type","id",idStr,fields,values); + } +} + + + bool LocationType::Load(iDocumentNode *node) { name = node->GetAttributeValue("name"); @@ -914,6 +951,40 @@ return location; } +LocationType* LocationManager::CreateLocationType(iDataConnection* db, const csString& locationName) +{ + LocationType* locationType = new LocationType(-1,locationName); + + if (locationType->CreateUpdate(db)) + { + loctypes.Put(locationName, locationType); + return locationType; + } + delete locationType; + return NULL; +} + +LocationType* LocationManager::CreateLocationType(int id, const csString& locationName) +{ + LocationType* locationType = new LocationType(id,locationName); + loctypes.Put(locationName, locationType); + return locationType; +} + + +bool LocationManager::RemoveLocationType(iDataConnection* db, const csString& locationName) +{ + return false; +} + + +bool LocationManager::RemoveLocationType(const csString& locationName) +{ + return false; +} + + + /*------------------------------------------------------------------*/ Modified: trunk/src/common/util/location.h =================================================================== --- trunk/src/common/util/location.h 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/common/util/location.h 2012-04-08 23:17:13 UTC (rev 8197) @@ -213,7 +213,6 @@ */ Location* Insert(int id, csVector3 &pos, iSector* sector); - }; /** @@ -229,10 +228,23 @@ csString name; ///< The name of this location type. csArray<Location*> locs; ///< All the location of this location type. + /** Constructor + */ + LocationType(); + + /** Constructor + */ + LocationType(int id, const csString& name); + /** Destructor */ ~LocationType(); + /** Create or update an entry for this location type in the DB. + * @note Will update if there is a id different from -1. + */ + bool CreateUpdate(iDataConnection* db); + /** Load a location type from an XML file. */ bool Load(iDocumentNode *node); @@ -351,6 +363,22 @@ */ Location* CreateLocation(LocationType* locationType, const char* locationName, csVector3& pos, iSector* sector, float radius, float rot_angle, const csString& flags); + /** Create a new location type + */ + LocationType* CreateLocationType(iDataConnection* db, const csString& locationName); + + /** Create a new location type + */ + LocationType* CreateLocationType(int id, const csString& locationName); + + /** Remove a location type + */ + bool RemoveLocationType(iDataConnection* db, const csString& locationName); + + /** Remove a location type + */ + bool RemoveLocationType(const csString& locationName); + private: csHash<LocationType*, csString> loctypes; ///< Hash on all location types, hashed on the type. csArray<Location*> all_locations; ///< Quick access array to all locations. Modified: trunk/src/npcclient/networkmgr.cpp =================================================================== --- trunk/src/npcclient/networkmgr.cpp 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/npcclient/networkmgr.cpp 2012-04-08 23:17:13 UTC (rev 8197) @@ -832,6 +832,7 @@ if (!location->SetFlag(msg.flags, msg.enable)) { Error3("Failed to set flag %s for location %d\n",msg.flags.GetDataSafe(),msg.id); + return; } Debug4(LOG_NET, 0, "Set flag %s for location %d to %s.\n", @@ -844,6 +845,30 @@ } break; + case psLocationMessage::LOCATION_TYPE_ADD: + { + LocationType* locationType = locations->CreateLocationType(msg.id,msg.typeName); + if (!locationType) + { + Error1("Failed to create location type"); + return; + } + Debug3(LOG_NET, 0, "Created location type %s(%d).\n", + locationType->GetName(),locationType->GetID()); + + } + break; + case psLocationMessage::LOCATION_TYPE_REMOVE: + { + if (!locations->RemoveLocationType(msg.typeName)) + { + return; + } + Debug2(LOG_NET, 0, "Removed location type %s.\n", + msg.typeName.GetDataSafe()); + + } + break; default: { Error2("Command %d for Location Handling not implemented\n",msg.command); Modified: trunk/src/server/adminmanager.cpp =================================================================== --- trunk/src/server/adminmanager.cpp 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/server/adminmanager.cpp 2012-04-08 23:17:13 UTC (rev 8197) @@ -3138,6 +3138,7 @@ subCommandList.Push("list",""); subCommandList.Push("radius","<radius> [<search radius>]"); subCommandList.Push("select","[<search radius>]"); + subCommandList.Push("type","add|delete [<type>]"); subCommandList.Push("show","See /path help display"); @@ -3215,6 +3216,26 @@ searchRadius = 10.0; } } + else if (subCommand == "type") + { + csString subSubCmd = words[index++]; + if (subSubCmd.IsEmpty()) + { + ParseError(me,"No sub command; add or delete given."); + } + else if (subSubCmd == "add") + { + subCommand = "type add"; + } + else if (subSubCmd == "delete" || subSubCmd == "remove") + { + subCommand = "type delete"; + } + if (!words.GetString(index++,locationType)) + { + ParseError(me,"No type given."); + } + } } // first wird is not a valid subcommand @@ -7407,7 +7428,44 @@ "Selected location %s(%d) at range %.2f.", location->GetName(), location->GetID(), distance); } + else if (data->subCommand == "type add") + { + LocationType* locationType = locations->FindLocation(data->locationType); + if (locationType) + { + psserver->SendSystemInfo(me->clientnum, "Location type %s already exists.",data->locationType.GetDataSafe()); + return; + } + + locationType = locations->CreateLocationType(db,data->locationType); + + if (locationType) + { + psserver->SendSystemInfo(me->clientnum, "New Location type %s(%d) created.",locationType->GetName(),locationType->GetID()); + psserver->npcmanager->LocationTypeAdd(locationType); + } + } + else if (data->subCommand == "type delete") + { + LocationType* locationType = locations->FindLocation(data->locationType); + if (!locationType) + { + psserver->SendSystemInfo(me->clientnum, "Found no location type named %s.",data->locationType.GetDataSafe()); + return; + } + + if (locations->RemoveLocationType(db,data->locationType)) + { + psserver->SendSystemInfo(me->clientnum, "Deleted Location type %s.",data->locationType.GetDataSafe()); + psserver->npcmanager->LocationTypeRemove(data->locationType); + } + } + else + { + Error2("Unknown type of location subCommand %s",data->subCommand.GetDataSafe()); + } + } Modified: trunk/src/server/database/mysql/sc_npctypes.sql =================================================================== --- trunk/src/server/database/mysql/sc_npctypes.sql 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/server/database/mysql/sc_npctypes.sql 2012-04-08 23:17:13 UTC (rev 8197) @@ -54,7 +54,7 @@ </behavior> <behavior name="RandomMoveInRegion" completion_decay="0" loop="yes" resume="yes"> - <wait duration="5" random="5" /> + <wait duration="15" random="5" /> <locate obj="region" range="20" random="yes" destination="Move" /> <percept event="local_move" /> <!-- Local navigation --> </behavior> @@ -65,23 +65,22 @@ INSERT INTO sc_npctypes VALUES("4","Fight","","","","","","","","1", '<behavior name="Fight" initial="0" growth="0" decay="0" completion_decay="-1" > <locate obj="target" range="20" /> - <talk text="$race attacked by $target" target="false" /> <rotate type="locatedest" anim="walk" ang_vel="120" /> <melee seek_range="25" melee_range="2" /> </behavior> <behavior name="Chase" initial="0" growth="0" decay="1" completion_decay="-1" > - <chase type="target" chase_range="25" offset="0.5" offset_angle="20" anim="run" vel="5" /> + <chase type="target" chase_range="25" offset="0.5" offset_angle="20" anim="run" vel="$run" /> </behavior> -<behavior name="FailedToAttack" completion_decay="-1" > - <talk text="I can not attack $target" target="false" /> +<behavior name="FailedToAttack" completion_decay="-1" resume="yes" > + <locate obj="point" range="30" destination="Move" /> + <percept event="local_move" /> <!-- Local navigation --> </behavior> -<behavior name="FailedEndpoint" completion_decay="-1" > - <talk text="I failed to reach $target going away" target="false" /> - <locate obj="point" range="30" /> - <navigate anim="walk" /> <!-- Local navigation --> +<behavior name="FailedEndpoint" completion_decay="-1" resume="yes" > + <locate obj="point" range="30" destination="Move" /> + <percept event="local_move" /> <!-- Local navigation --> </behavior> @@ -1168,15 +1167,15 @@ <react event="spell:target" type="direct heal" behavior="Drain" delta="100" /> '); -INSERT INTO sc_npctypes VALUES("125","Fighter5","DoNothing,Move,Diurnal","","$walk","","","","","0", +INSERT INTO sc_npctypes VALUES("125","Fighter5","DoNothing,Move,Diurnal,Fight","","$walk","","","","","0", '<empty/> '); -INSERT INTO sc_npctypes VALUES("126","Fighter6","DoNothing,Move,Diurnal","","$walk","","","","","0", +INSERT INTO sc_npctypes VALUES("126","Fighter6","DoNothing,Move,Diurnal,Fight","","$walk","","","","","0", '<empty/> '); -INSERT INTO sc_npctypes VALUES("127","Fighter7","DoNothing,Move,Nocturnal","","$walk","","","","","0", +INSERT INTO sc_npctypes VALUES("127","Fighter7","DoNothing,Move,Nocturnal,Fight","","$walk","","","","","0", '<empty/> '); -INSERT INTO sc_npctypes VALUES("128","Fighter8","DoNothing,Move,Nocturnal","","$walk","","","","","0", +INSERT INTO sc_npctypes VALUES("128","Fighter8","DoNothing,Move,Nocturnal,Fight","","$walk","","","","","0", '<empty/> '); Modified: trunk/src/server/npcmanager.cpp =================================================================== --- trunk/src/server/npcmanager.cpp 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/server/npcmanager.cpp 2012-04-08 23:17:13 UTC (rev 8197) @@ -2791,13 +2791,31 @@ void NPCManager::LocationRadius(Location* location) { - Debug3(LOG_SUPERCLIENT, 0, "NPCManager chaned radius of location (%s)%d\n", location->GetName(), location->GetID()); + Debug3(LOG_SUPERCLIENT, 0, "NPCManager changed radius of location (%s)%d\n", location->GetName(), location->GetID()); psLocationMessage msg(psLocationMessage::LOCATION_RADIUS, location); msg.Multicast(superclients, -1, PROX_LIST_ANY_RANGE); } +void NPCManager::LocationTypeAdd(LocationType* locationType) +{ + Debug3(LOG_SUPERCLIENT, 0, "NPCManager added new location type (%s)%d\n", locationType->GetName(), locationType->GetID()); + + psLocationMessage msg(psLocationMessage::LOCATION_TYPE_ADD, locationType); + + msg.Multicast(superclients, -1, PROX_LIST_ANY_RANGE); +} + +void NPCManager::LocationTypeRemove(const csString& locationTypeName) +{ + Debug2(LOG_SUPERCLIENT, 0, "NPCManager removed location type (%s)\n", locationTypeName.GetDataSafe()); + + psLocationMessage msg(psLocationMessage::LOCATION_TYPE_REMOVE, locationTypeName); + + msg.Multicast(superclients, -1, PROX_LIST_ANY_RANGE); +} + void NPCManager::WaypointAdjusted(Waypoint* wp) { Debug2(LOG_SUPERCLIENT, 0, "NPCManager ajusting waypoint %d\n", wp->GetID()); Modified: trunk/src/server/npcmanager.h =================================================================== --- trunk/src/server/npcmanager.h 2012-04-08 20:48:14 UTC (rev 8196) +++ trunk/src/server/npcmanager.h 2012-04-08 23:17:13 UTC (rev 8197) @@ -55,6 +55,7 @@ class Waypoint; class psPath; class Location; +class LocationType; class NPCManager : public MessageManager<NPCManager> { @@ -198,6 +199,16 @@ */ void LocationRadius(Location* location); + /** Notify superclients that a location type has been added. + * @param locationType The location type that has been created. + */ + void LocationTypeAdd(LocationType* locationType); + + /** Notify superclients that a location type has been deleted. + * @param locationTypeName The name of the location type that has been deleted. + */ + void LocationTypeRemove(const csString& locationTypeName); + /** Notify superclients that a waypoint where adjusted. * @param wp The waypoint that has been adjusted. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |