From: Marc H. <sto...@us...> - 2002-06-12 14:07:02
|
Update of /cvsroot/planeshift/planeshift/src/server In directory usw-pr-cvs1:/tmp/cvs-serv3908/server Modified Files: pscelserver.cpp pscelserver.h psdatabase.cpp psdatabase.h psserver.cpp usermanager.cpp Log Message: -added sector support to the database -updated export2.sql and export5.sql accordingly -added sector support to the server (making /pos and /spawn work correctly) -updated pslinmove to tell the sector name Index: pscelserver.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/pscelserver.cpp,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** pscelserver.cpp 6 Jun 2002 06:59:01 -0000 1.61 --- pscelserver.cpp 12 Jun 2002 14:06:58 -0000 1.62 *************** *** 26,29 **** --- 26,30 ---- #include <iutil/objreg.h> #include <iutil/cfgmgr.h> + #include <iutil/object.h> #include <csgeom/box.h> *************** *** 168,171 **** --- 169,230 ---- } + + iSector* psCelServer::FindSpawnSector(int objectID) + { + iSector* res = 0; + if (objectID) + { + char* sectorName = 0; + + sectorName = database->GetObjectSector(objectID); + if ((!sectorName) || (!strcmp(sectorName, "(null)"))) + { + fprintf(stderr, "[psCelServer::FindSpawnSector] Sector name is empty ! Setting to \"room\"\n"); + sectorName="room"; + } + res = engine->GetSectors()->FindByName(sectorName); + if (!res) + fprintf (stderr, "[psCelServer::FindSpawnSector] Sector \"%s\" not found for object %i !\n", sectorName, objectID); + + return res; + } + + static int num=0; + + // look if the user specified a spawn sector + iConfigManager* cfgmgr = psserver->GetConfig(); + bool use_usersec = cfgmgr->GetBool("Planeshift.Server.User.UseUserSpawn", false); + + if (use_usersec) + { + iConfigManager* cfgmgr = psserver->GetConfig(); + res = engine->GetSectors()->FindByName(cfgmgr->GetStr ("Planeshift.Server.User.SpawnSector", "room")); + if (!res) + fprintf (stderr, "[psCelServer::FindSpawnSector] Sector \"%s\" not found !\n", cfgmgr->GetStr ("Planeshift.Server.User.SpawnSector", "room")); + return res; + } + + // look through engine list of camera start positions + iCameraPositionList* camposlist = engine->GetCameraPositions(); + + if (camposlist->GetCount()==0) + { + fprintf (stderr, "[psCelServer::FindSpawnSector] Start sector list in map is empty ! Starting in \"room\" !\n"); + res = engine->GetSectors()->FindByName("room"); + if (!res) + fprintf (stderr, "[psCelServer::FindSpawnSector] Start sector \"room\" not found !\n"); + + return res; + + } + + iCameraPosition* campos = camposlist->Get(num % camposlist->GetCount()); + res = engine->GetSectors()->FindByName(campos->GetSector()); + if (!res) + fprintf (stderr, "[psCelServer::FindSpawnSector] Camera sector %s not found !\n", campos->GetSector()); + + return res; + } + bool psCelServer::CreatePlayer (Client* client) { *************** *** 184,187 **** --- 243,247 ---- iCelEntity* entity = CreateActor(factname, FindSpawnPosition(client->GetObjectID()), + FindSpawnSector(client->GetObjectID()), client->GetPlayerID()); if (!entity) *************** *** 221,224 **** --- 281,285 ---- iCelEntity* npcentity = CreateActor(factname, FindSpawnPosition(objectID), + FindSpawnSector(objectID), NPCID); if (!npcentity) *************** *** 325,329 **** } ! bool psCelServer::InitMesh(iPcMesh *pcmesh,const char* factname,const csVector3& pos) { // Now that the mesh is created, initialize it by loading the sprite file. --- 386,390 ---- } ! bool psCelServer::InitMesh(iPcMesh *pcmesh,const char* factname,const csVector3& pos, const iSector* sector) { // Now that the mesh is created, initialize it by loading the sprite file. *************** *** 338,343 **** return false; } ! psWorld* psworld = psWorld::GetPSWorld(GetWorldEntity()); ! // pos should be relative to middlepoint iMeshWrapper* mesh = pcmesh->GetMesh(); --- 399,403 ---- return false; } ! // pos should be relative to middlepoint iMeshWrapper* mesh = pcmesh->GetMesh(); *************** *** 350,354 **** mesh->GetTransformedBoundingBox(t, box); newpos -= box.GetCenter(); ! pcmesh->MoveMesh (psworld->GetRoom(), newpos); pcmesh->SetAction ("stand"); pcmesh->DecRef(); --- 410,414 ---- mesh->GetTransformedBoundingBox(t, box); newpos -= box.GetCenter(); ! pcmesh->MoveMesh ((iSector*)sector, newpos); // UGLY: casting that const away pcmesh->SetAction ("stand"); pcmesh->DecRef(); *************** *** 430,434 **** ! iCelEntity* psCelServer::CreateActor (const char* factname, const csVector3& pos,int playerID) { iCelPropertyClass* pc; --- 490,494 ---- ! iCelEntity* psCelServer::CreateActor (const char* factname, const csVector3& pos, const iSector* sector, int playerID) { iCelPropertyClass* pc; *************** *** 441,445 **** if (!pc) { ! entity->DecRef(); return NULL; } --- 501,505 ---- if (!pc) { ! entity->DecRef(); return NULL; } *************** *** 447,454 **** if (!pcmesh) { ! entity->DecRef(); return NULL; } ! if (!InitMesh(pcmesh,factname,pos)) { pcmesh->DecRef(); --- 507,514 ---- if (!pcmesh) { ! entity->DecRef(); return NULL; } ! if (!InitMesh(pcmesh,factname,pos,sector)) { pcmesh->DecRef(); Index: pscelserver.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/pscelserver.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** pscelserver.h 6 Jun 2002 06:59:01 -0000 1.18 --- pscelserver.h 12 Jun 2002 14:06:58 -0000 1.19 *************** *** 52,55 **** --- 52,56 ---- const csVector3 FindSpawnPosition(int objectID=0); + iSector* FindSpawnSector(int objectID=0); bool CreatePlayer(Client* client); bool CreateNPC(int NPCID); *************** *** 61,67 **** protected: iCelEntity* CreateRoom (const char* name, const char* mapfile); ! iCelEntity* CreateActor (const char* factname, const csVector3& pos,int playerID); ! bool InitMesh(iPcMesh *pcmesh,const char* factname,const csVector3& pos); bool InitLinMove(iPcLinearMovement *pcmove); bool InitCharData(iPcCharacterData *pcdata,int playerID); --- 62,68 ---- protected: iCelEntity* CreateRoom (const char* name, const char* mapfile); ! iCelEntity* CreateActor (const char* factname, const csVector3& pos, const iSector* sector, int playerID); ! bool InitMesh(iPcMesh *pcmesh,const char* factname,const csVector3& pos,const iSector* sector); bool InitLinMove(iPcLinearMovement *pcmove); bool InitCharData(iPcCharacterData *pcdata,int playerID); Index: psdatabase.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/psdatabase.cpp,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** psdatabase.cpp 6 Jun 2002 06:59:01 -0000 1.42 --- psdatabase.cpp 12 Jun 2002 14:06:58 -0000 1.43 *************** *** 821,824 **** --- 821,854 ---- } + char* psDatabase::GetObjectSector(int objID) + { + printf("Getting Object %d Sector: ", objID); + + Result result (mysql->Select("select sector " + " from objects " + " where id=%d ", objID)); + + if (!result.IsValid()) + { + lasterror = GetLastSQLError(); + return NULL; + } + + + if (result.Count() != 1) + { + lasterror = GetLastSQLError(); + return NULL; + } + + int len = strlen(result[0][0]) + 1; // include NULL string termination ! + char* sectorName = (char*) malloc (len); + strncpy (sectorName, result[0][0], len); + + printf("%s\n", sectorName); + + return sectorName; + } + bool psDatabase::SetObjectPosition(int objID, float x, float y, float z) { *************** *** 829,832 **** --- 859,878 ---- " WHERE id=%d", x,y,z,objID) != 1 ) + { + lasterror = GetLastSQLError(); + return false; + } + + return true; + } + + bool psDatabase::SetObjectSector(int objID, const char* sectorName) + { + printf("Updating Object %d Sector: %s\n", objID, sectorName); + + if (mysql->Command("UPDATE objects " + " SET sector='%s'" + " WHERE id=%d", + sectorName, objID) != 1 ) { lasterror = GetLastSQLError(); Index: psdatabase.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/psdatabase.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** psdatabase.h 6 Jun 2002 06:59:01 -0000 1.22 --- psdatabase.h 12 Jun 2002 14:06:58 -0000 1.23 *************** *** 137,143 **** --- 137,149 ---- /// Gets x,y,z locations for specified Object. Returns false if fails. bool GetObjectPosition(int objID, float& x, float& y, float& z); + + /// Gets the sector name for specified object. Returns NULL if fails. + char* GetObjectSector(int objID); /// Updates x,y,z locations for specified Object. Returns false if fails. bool SetObjectPosition(int objID, float x, float y, float z); + + /// Updates sector name for specified object. Returns false if fails. + bool SetObjectSector(int objID, const char* sectorName); /// Adds the specified item to player inventory Index: psserver.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/psserver.cpp,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** psserver.cpp 6 Jun 2002 06:59:01 -0000 1.58 --- psserver.cpp 12 Jun 2002 14:06:58 -0000 1.59 *************** *** 22,25 **** --- 22,26 ---- #include <iutil/cfgmgr.h> #include <iutil/cmdline.h> + #include <iutil/object.h> #include <ivaria/reporter.h> *************** *** 276,279 **** --- 277,281 ---- // Get the current position of the actor and save in database. csVector3 pos; + iSector* sector = 0; iPcLinearMovement* linmove = *************** *** 282,287 **** if (linmove) { ! linmove->GetLastPosition(pos); ! database->SetObjectPosition(client->GetObjectID(),pos.x,pos.y,pos.z); linmove->DecRef(); } --- 284,296 ---- if (linmove) { ! linmove->GetLastPosition(pos, sector); ! database->SetObjectPosition(client->GetObjectID(),pos.x,pos.y,pos.z); ! ! if (!sector) ! fprintf (stderr, "[psServer::RemovePlayer] NULL sector in RemovePlayer ! Can't store sector name !\n"); ! else ! if (!database->SetObjectSector(client->GetObjectID(),sector->QueryObject()->GetName())) ! fprintf (stderr, "[psServer::RemovePlayer] Error storing sector name !\n"); ! linmove->DecRef(); } Index: usermanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/usermanager.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** usermanager.cpp 8 Jun 2002 22:56:53 -0000 1.23 --- usermanager.cpp 12 Jun 2002 14:06:58 -0000 1.24 *************** *** 368,381 **** csVector3 pos; ! iSectorList *sector_list = pcmesh->GetMesh()->GetMovable()->GetSectors(); ! const char *sector_name; ! if(sector_list->GetCount() > 0) ! sector_name = sector_list->Get(0)->QueryObject()->GetName(); ! else sector_name = "(null)"; ! ! linmove->GetLastPosition(pos); psSystemMessage newmsg(clientnum, --- 368,380 ---- csVector3 pos; + iSector* sector = 0; ! linmove->GetLastPosition(pos, sector); ! const char *sector_name; ! if(!sector) sector_name = "(null)"; ! else ! sector_name = sector->QueryObject()->GetName(); psSystemMessage newmsg(clientnum, *************** *** 397,402 **** { csVector3 pos; ! pos = celserver->FindSpawnPosition(NULL); // no client specified means std spawn pt iPcLinearMovement* linmove = --- 396,403 ---- { csVector3 pos; + iSector* sector = 0; ! pos = celserver->FindSpawnPosition(0); // no client specified means std spawn pt ! sector = celserver->FindSpawnSector(0); // no client specified means std spawn sector iPcLinearMovement* linmove = *************** *** 409,418 **** } ! linmove->SetPosition(pos); ! psSystemMessage newmsg(clientnum, ! "Moving back to spawn point..."); - msghandler->SendMessage(newmsg.msg); iDataBuffer* data = linmove->GetDRData(); --- 410,428 ---- } ! linmove->SetPosition(pos, sector); ! if (sector) ! { ! psSystemMessage newmsg(clientnum, ! "Moving back to spawn point in sector %s...", sector->QueryObject()->GetName()); ! msghandler->SendMessage(newmsg.msg); ! } ! else ! { ! psSystemMessage newmsg(clientnum, ! "Moving back to spawn point in null sector..."); ! msghandler->SendMessage(newmsg.msg); ! } iDataBuffer* data = linmove->GetDRData(); |