Add infos into target window
[ryzomcore.git] / ryzom / server / src / gpm_service / messages.cpp
blobec15251b08a7b9b4810728983551cea1763a52bd
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
19 // include files
20 #include "nel/misc/types_nl.h"
22 #include "game_share/utils.h"
24 #include "server_share/r2_variables.h"
25 #include "game_share/r2_messages.h"
27 #include "gpm_service.h"
28 #include "messages.h"
29 #include "world_position_manager.h"
31 //#include "game_share/tick_event_handler.h"
32 //#include "game_share/msg_client_server.h"
33 //#include "game_share/mode_and_behaviour.h" //TEMP!!!
34 //#include "game_share/news_types.h"
35 //#include "game_share/bot_chat_types.h"
36 //#include "game_share/brick_types.h"
37 //#include "game_share/loot_harvest_state.h"
38 //#include "game_share/synchronised_message.h"
40 using namespace std;
41 using namespace NLMISC;
42 using namespace NLNET;
47 /****************************************************************\
48 cbAddEntity()
49 \****************************************************************/
51 void cbAddEntity( CMessage& msgin, const string &serviceName, uint16 serviceId )
53 // Only for invisible group entities (other entities use the mirror system)
55 CEntityId id;
56 msgin.serial( id );
58 // entity pos (x, y, z, theta) at tick
59 sint32 x;
60 msgin.serial( x );
61 sint32 y;
62 msgin.serial( y );
63 sint32 z;
64 msgin.serial( z );
65 float t;
66 msgin.serial( t );
68 // the tick when this entity should be added
69 //--------------------------------- DEBUG ONLY--------------------------------
70 NLMISC::TGameCycle tick;
71 //msgin.serial( tick );
72 tick = CTickEventHandler::getGameCycle();
73 //--------------------------------- DEBUG ONLY--------------------------------
75 // entity sheet
76 CSheetId sheet;
77 msgin.serial( sheet );
79 uint8 continent = INVALID_CONTINENT_INDEX;
80 if (msgin.getPos() != (sint32)msgin.length())
81 msgin.serial(continent);
83 sint32 cell = 0;
84 if (msgin.getPos() != (sint32)msgin.length())
85 msgin.serial(cell);
87 nlinfo("<cbAddEntity> Add entity %s at pos (%d,%d,%d)", id.toString().c_str(), x,y,z );
88 CWorldPositionManager::addEntity( id, x, y, z, t, continent, cell, tick, sheet, id.getDynamicId() );
89 } // cbAddEntity //
92 /****************************************************************\
93 cbAddIAObject()
94 \****************************************************************/
96 void cbAddIAObject( CMessage& msgin, const string &serviceName, uint16 serviceId )
98 nlerror( "TODO: process ADD_IA_OBJECT" );
103 /****************************************************************\
104 cbAddEntities()
105 \****************************************************************/
106 /*void cbAddEntities( CMessage& msgin, const string &serviceName, uint16 serviceId )
108 //nlinfo("received ADD_ENTITIES request");
110 uint32 entitiesCount;
111 msgin.serial( entitiesCount );
113 for( uint32 i = 0; i < entitiesCount; i++ )
115 CEntityId id;
116 msgin.serial( id );
118 // entity pos (x, y, z, theta) at tick
119 sint32 x;
120 msgin.serial( x );
121 sint32 y;
122 msgin.serial( y );
123 sint32 z;
124 msgin.serial( z );
125 float t;
126 msgin.serial( t );
128 // the tick when this entity should be added
129 //--------------------------------- DEBUG ONLY--------------------------------
130 NLMISC::TGameCycle tick;
131 //msgin.serial( tick );
132 tick = CTickEventHandler::getGameCycle();
133 //--------------------------------- DEBUG ONLY--------------------------------
135 // entity sheet
136 CSheetId sheet;
137 msgin.serial( sheet );
139 nlinfo("<cbAddEntities> Add entity %s at pos (%d,%d,%d)", id.toString().c_str(), x,y,z );
140 CWorldPositionManager::addEntity(id, x, y, z, t, INVALID_CONTINENT_INDEX, 0, tick, sheet, id.getDynamicId() );
142 } // cbAddEntities //
145 /****************************************************************\
146 cbRemoveEntity()
147 \****************************************************************/
149 void cbRemoveEntity( CMessage& msgin, const string &serviceName, uint16 serviceId )
151 // Only for invisible group entities (other entities use the mirror system)
153 CEntityId id;
154 id.serial( msgin );
156 nlinfo("received REMOVE_ENTITY request for id %s", id.toString().c_str() );
158 CWorldPositionManager::onRemoveEntity( id );
160 } // cbRemoveEntity //
163 /****************************************************************\
164 cbRemoveEntities()
165 \****************************************************************/
166 /*void cbRemoveEntities( CMessage& msgin, const string &serviceName, uint16 serviceId )
168 nlinfo("received REMOVE_ENTITIES request");
170 list<CEntityId> ids;
171 msgin.serialCont( ids );
173 list<CEntityId> idsAgents;
175 list<CEntityId>::iterator it;
176 for( it = ids.begin(); it!=ids.end(); ++it )
178 CWorldPositionManager::removeEntity( *it );
179 nlinfo(" REMOVE_ENTITY id %s", (*it).toString().c_str() );
181 if( (*it).getType() == RYZOMID::npc )
183 idsAgents.push_back( *it );
187 if( idsAgents.size() != 0 )
189 CMessage msgout("REMOVE_ENTITY");
191 for ( it = idsAgents.begin() ; it != idsAgents.end() ; ++it)
192 msgout.serial( const_cast<CEntityId&> (*it) );
194 sendMessageViaMirror( "AgS", msgout );
197 }*/ // cbRemoveEntities //
200 /****************************************************************\
201 CGPMPlayerPrivilegeInst::callback
202 \****************************************************************/
203 void CGPMPlayerPrivilegeInst::callback (const std::string &name, NLNET::TServiceId id)
205 CWorldEntity* entity = CWorldPositionManager::getEntityPtr(PlayerIndex);
207 if (entity == NULL || entity->PlayerInfos == NULL)
209 nlwarning("CGPMPlayerPrivilegeInst::callback(): entity '%d' is not a player", PlayerIndex.getIndex());
210 return;
213 // enable/disable speed checking, only enabled for basic players
214 entity->PlayerInfos->CheckSpeed = (Type == CGPMPlayerPrivilege::Player);
217 /****************************************************************\
218 cbSetPlayerFlags()
219 \****************************************************************/
220 void cbSetPlayerFlags( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
222 R2::CMessageSetGPMSPlayerFlags msgData;
223 msgin.serial(msgData);
225 CWorldEntity* entity = CWorldPositionManager::getEntityPtr(msgData.PlayerIndex);
227 DROP_IF(entity == NULL || entity->PlayerInfos == NULL, NLMISC::toString("cbSetPlayerFlags(): entity '%d' is not a player", msgData.PlayerIndex.getIndex()), return);
229 // enable/disable speed checking, only enabled for basic players
230 entity->PlayerInfos->CheckSpeed = msgData.LimitSpeed;
233 /****************************************************************\
234 cbBag()
235 \****************************************************************/
236 void cbBag( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
238 CEntityId id;
239 vector<CEntitySheetId> content;
241 msgin.serial(id);
242 msgin.serialCont(content);
244 TDataSetRow index = CWorldPositionManager::getEntityIndex(id);
246 CWorldPositionManager::setContent(index, content);
248 } // cbBag //
251 /****************************************************************\
252 cbLoadContinent()
253 \****************************************************************/
254 void cbLoadContinent( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
256 uint8 continent;
257 string name;
258 string file;
260 // load continent index
261 msgin.serial(continent);
263 // load continent name
264 msgin.serial(name);
266 // load continent filename
267 msgin.serial(file);
269 // load continent in position manager
270 CWorldPositionManager::loadContinent(name, file, continent);
273 /****************************************************************\
274 cbRemoveContinent()
275 \****************************************************************/
276 void cbRemoveContinent( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
278 uint8 continent;
280 // load continent index
281 msgin.serial(continent);
283 // remove continent from position manager
284 CWorldPositionManager::removeContinent(continent);
288 /****************************************************************\
289 cbCreateIndoorUnit()
290 \****************************************************************/
291 void cbCreateIndoorUnit( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
293 DROP_IF(IsRingShard,"Creating indoor units not supported on ring shards!",return);
295 sint32 cell;
297 // cell id (should be >= 2)
298 msgin.serial(cell);
300 if (cell < 2)
302 nlwarning("cbCreateIndoorUnit(): try to create unit using id < 2");
303 return;
306 CWorldPositionManager::createIndoorCell(cell);
308 nlinfo("MSG: Creating indoor unit %d",cell);
311 /****************************************************************\
312 cbCreateBuilding()
313 \****************************************************************/
314 void cbCreateBuilding( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
316 uint8 continent;
317 string id;
318 CVectorD position;
320 msgin.serial(continent);
321 msgin.serial(id);
322 msgin.serial(position);
324 CWorldPositionManager::createBuildingInstance(continent, id, position);
327 /****************************************************************\
328 cbCreateObstacle()
329 \****************************************************************/
330 void cbCreateObstacle( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
332 string id, file;
333 CVectorD position;
334 float angle;
336 while (msgin.getPos() < (sint32)msgin.length())
338 msgin.serial(id, file, position, angle);
339 CWorldPositionManager::instanciatePacsPrim(id, file, position, angle);
343 /****************************************************************\
344 cbRemoveObstacle()
345 \****************************************************************/
346 void cbRemoveObstacle( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
348 string id;
350 while (msgin.getPos() < (sint32)msgin.length())
352 msgin.serial(id);
353 CWorldPositionManager::removePacsPrim(id);
357 /****************************************************************\
358 cbSetObstacle()
359 \****************************************************************/
360 void cbSetObstacle( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
362 string id;
363 bool obstacle;
365 while (msgin.getPos() < (sint32)msgin.length())
367 msgin.serial(id, obstacle);
368 CWorldPositionManager::setObstacle(id, obstacle);
372 /****************************************************************\
373 cbUpdateEntityPosition()
374 \****************************************************************/
376 void cbUpdateEntityPosition( CMessage& msgin, const string &serviceName, uint16 serviceId )
378 H_BEFORE(cbUpdatePosition);
379 //Use only for tp, update position and clear behaviours list
380 //nlinfo("received UPDATE_ENTITY_POSITION request");
382 CEntityId id;
383 id.serial( msgin );
385 // entity pos (x, y, z, theta) at tick
386 sint32 x;
387 msgin.serial( x );
388 sint32 y;
389 msgin.serial( y );
390 sint32 z;
391 msgin.serial( z );
392 float t;
393 msgin.serial( t );
394 NLMISC::TGameCycle tick;
395 msgin.serial( tick );
397 // nlwarning("GPMS Received Update Position, Pos(%.3f,%.3f,%.3f), theta = %.3f", x, y, z,t );
399 CWorldPositionManager::setEntityPosition(id, x, y, z, t, tick);
400 H_AFTER(cbUpdatePosition);
401 } // cbUpdateEntityPosition //
404 /****************************************************************\
405 cbUpdateEntitiesPositions()
406 \****************************************************************/
408 void cbUpdateEntitiesPositions( CMessage& msgin, const string &serviceName, uint16 serviceId )
410 H_BEFORE(cbUpdatePositions);
411 //Use only for tp, update position and clear behaviours list
412 //nlinfo("received UPDATE_ENTITIES_POSITIONS request");
414 uint16 entitiesCount;
415 msgin.serial( entitiesCount );
417 NLMISC::CEntityId sid;
418 sint32 x, y, z;
419 float t;
420 NLMISC::TGameCycle tick;
422 for (uint16 i = 0 ; i < entitiesCount ; ++i)
424 msgin.serial( sid );
425 msgin.serial( x );
426 msgin.serial( y );
427 msgin.serial( z );
428 msgin.serial( t );
429 msgin.serial( tick );
431 //nlinfo("Entity %s: received (%.3f,%.3f,%.3f), theta = %.3f", sid.toString().c_str(), x*0.001, y*0.001, z*0.001,t );
433 CWorldPositionManager::setEntityPosition(sid, x, y, z, t, tick);
436 H_AFTER(cbUpdatePositions);
437 } // cbUpdateEntitiesPositions //
440 /****************************************************************\
441 cbUpdateEntitiesPositions()
442 \****************************************************************/
444 void cbUpdateEntitiesPositionsUsingSize( CMessage& msgin, const string &serviceName, uint16 serviceId )
446 H_BEFORE(cbUpdatePositions);
447 //nlinfo("received UPDATE_ENTITIES_POSITIONS request");
449 NLMISC::CEntityId sid;
450 sint32 x, y, z;
451 float t;
452 NLMISC::TGameCycle tick;
454 while (msgin.getPos() < (sint32)msgin.length())
456 msgin.serial( sid );
457 msgin.serial( x );
458 msgin.serial( y );
459 msgin.serial( z );
460 msgin.serial( t );
461 msgin.serial( tick );
463 //nlinfo("Entity %s: received (%.3f,%.3f,%.3f), theta = %.3f", id.toString().c_str(), x*0.001, y*0.001, z*0.001,t );
465 CWorldPositionManager::setEntityPosition(sid, x, y, z, t, tick);
468 H_AFTER(cbUpdatePositions);
469 } // cbUpdateEntitiesPositions //
473 /// Update orientation of several entities
474 void cbUpdateEntitiesOrientations( CMessage& msgin, const string &serviceName, uint16 serviceId )
476 /// Update position of several entities (for re-spawn, position correction, server resync...)
477 void cbUpdateEntitiesPositionsUsingSize( CMessage& msgin, const string &serviceName, uint16 serviceId )
479 /// Update orientation of several entities
480 void cbUpdateEntitiesOrientationsUsingSize( CMessage& msgin, const string &serviceName, uint16 serviceId )
485 /****************************************************************\
486 cbEntityTeleport()
487 \****************************************************************/
488 void cbEntityTeleportation( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
490 CEntityId id;
491 NLMISC::TGameCycle tick;
493 id.serial( msgin );
494 TDataSetRow index = CWorldPositionManager::getEntityIndex(id);
496 if (!index.isValid())
497 return;
499 // if no position provided, teleport entity to nowhere
500 if (msgin.getPos() == (sint32)msgin.length())
502 if (IsRingShard)
504 // update the entity position in the ring vision universe
505 pCGPMS->RingVisionUniverse->setEntityPosition(index,0,0);
507 // update the player coordinates in the mirror
508 CMirrorPropValue1DS<sint32>( TheDataset, index, DSPropertyPOSX )= 0;
509 CMirrorPropValue1DS<sint32>( TheDataset, index, DSPropertyPOSY )= 0;
510 CMirrorPropValue1DS<sint32>( TheDataset, index, DSPropertyPOSZ )= 0;
512 else
514 CWorldPositionManager::teleport(index, 0, 0, 0, 0.0f, NO_CONTINENT_INDEX, 0, CTickEventHandler::getGameCycle());
517 nlinfo("MSG: Teleporting entity %d to continent 0 (0, 0, 0)",index.getIndex());
518 return;
521 // entity pos (x, y, z, theta) at tick
522 sint32 x;
523 msgin.serial( x );
524 sint32 y;
525 msgin.serial( y );
526 sint32 z;
527 msgin.serial( z );
528 float t;
529 msgin.serial( t );
531 msgin.serial( tick );
533 // use default continent 0
534 uint8 continent = INVALID_CONTINENT_INDEX;
535 if (msgin.getPos() != (sint32)msgin.length())
536 msgin.serial(continent);
538 sint32 cell = 0;
539 if (msgin.getPos() != (sint32)msgin.length())
540 msgin.serial(cell);
542 if (cell > 0)
544 //nlwarning("cbEntityTeleportation(): cell=%d for %s should be zero or negative, forced to 0", cell, id.toString().c_str());
545 cell = 0;
548 uint8 move_to_new_cell = 0;
549 if (msgin.getPos() != (sint32)msgin.length())
550 msgin.serial(move_to_new_cell);
552 if (IsRingShard)
554 // update the ring vision universe position
555 pCGPMS->RingVisionUniverse->setEntityPositionDelayed(index,x,y,tick);
557 // tell the move checker to teleport the entity too
558 pCGPMS->MoveChecker->teleport(index, x, y, tick);
560 // update the player coordinates in the mirror
561 CMirrorPropValue1DS<sint32>( TheDataset, index, DSPropertyPOSX )= x;
562 CMirrorPropValue1DS<sint32>( TheDataset, index, DSPropertyPOSY )= y;
563 CMirrorPropValue1DS<sint32>( TheDataset, index, DSPropertyPOSZ )= z;
564 CMirrorPropValue1DS<float>( TheDataset, index, DSPropertyORIENTATION )= t;
566 else
568 if (move_to_new_cell == 1)
570 //nlinfo("MSG: Sliding entity %d to cell %d) at tick: %d",index.getIndex(),cell,tick);
571 CWorldPositionManager::updateEntityPosition(CWorldPositionManager::getEntityPtr(index), cell);
573 else
575 //nlinfo("MSG: Teleporting entity %d to continent %d cell %d (%d, %d, %d) at tick: %d",index.getIndex(),continent,cell,x,y,z,tick);
576 CWorldPositionManager::teleport(index, x, y, z, t, continent, cell, tick);
581 // lock entity after a real teleport
582 CWorldPositionManager::lock(index, 10);
584 } // cbEntityTeleportation //
587 /****************************************************************\
588 cbEntityPosition()
589 \****************************************************************/
590 void cbEntityPosition( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
592 // CEntityId sender;
593 // sender.serial( msgin );
595 CEntityId id;
596 id.serial( msgin );
598 TDataSetRow index = CWorldPositionManager::getEntityIndex(id);
600 const CWorldEntity *pEntity = CWorldPositionManager::getEntity( index );
602 if( pEntity )
604 CMessage msgout( "ENTITY_POS" );
606 // msgout.serial( sender );
607 msgout.serial( id );
609 sint32 val;
610 val = pEntity->X();
611 msgout.serial( val );
613 val = pEntity->Y();
614 msgout.serial( val );
616 val = pEntity->Z();
617 msgout.serial( val );
619 float t = pEntity->Theta();
620 msgout.serial( t );
622 sendMessageViaMirror (serviceId, msgout);
624 else
626 nlwarning("Entity position : entity %s is not in the GPMS", id.toString().c_str());
629 } // cbEntityPosition //
631 /****************************************************************\
632 Attach child entity to a father
633 \****************************************************************/
634 void cbAttach( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
636 CEntityId father, child;
637 sint32 x, y, z;
639 msgin.serial(father);
640 msgin.serial(child);
641 msgin.serial(x, y, z);
643 TDataSetRow indexFather = CWorldPositionManager::getEntityIndex(father);
644 TDataSetRow indexChild = CWorldPositionManager::getEntityIndex(child);
646 CWorldPositionManager::attach(indexFather, indexChild, x, y, z);
649 /****************************************************************\
650 Detach child entity of its current father
651 \****************************************************************/
652 void cbDetach( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
654 CEntityId child;
656 msgin.serial(child);
658 TDataSetRow childIndex = CWorldPositionManager::getEntityIndex(child);
660 CWorldPositionManager::detach(childIndex);
663 /****************************************************************\
664 set player dead status
665 \****************************************************************/
666 void cbSetDeadStatus( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
668 CEntityId player;
669 bool status;
671 msgin.serial(player);
672 msgin.serial(status);
674 TDataSetRow index = CWorldPositionManager::getEntityIndex(player);
675 CWorldEntity *entity = CWorldPositionManager::getEntityPtr(index);
676 entity->Dead = status;
677 if (status)
678 nlinfo("player status changed to dead");
679 else
680 nlinfo("player status changed to alive");
684 /****************************************************************\
685 acquire control
686 \****************************************************************/
687 void cbAcquireControl( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
689 CEntityId slave, master;
690 sint32 x, y, z;
692 msgin.serial(slave, master);
693 msgin.serial(x, y, z);
695 TDataSetRow indexSlave = CWorldPositionManager::getEntityIndex(slave);
696 TDataSetRow indexMaster = CWorldPositionManager::getEntityIndex(master);
698 CWorldPositionManager::acquireControl(indexSlave, indexMaster, x, y, z);
700 if (IsRingShard)
702 pCGPMS->RingVisionUniverse->setEntityPosition(indexMaster,x,y);
703 pCGPMS->RingVisionUniverse->setEntityPosition(indexSlave,x,y);
706 nlinfo("MSG: Master %s acquire control of slave %s at (%d, %d, %d)",master.toString().c_str(),slave.toString().c_str(),x,y,z);
711 /****************************************************************\
712 leave control
713 \****************************************************************/
714 void cbLeaveControl( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
716 CEntityId master;
718 msgin.serial(master);
720 TDataSetRow indexMaster = CWorldPositionManager::getEntityIndex(master);
722 CWorldPositionManager::leaveControl(indexMaster);
724 nlinfo("MSG: Master %s release control of slave",master.toString().c_str());
728 /****************************************************************\
729 activate player self slot
730 \****************************************************************/
731 void cbActivateSelf( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
733 #ifdef HANDLE_SLOT0_SPECIAL
734 CEntityId id;
736 msgin.serial(id);
738 TDataSetRow index = CWorldPositionManager::getEntityIndex(id);
739 CWorldEntity *entity = CWorldPositionManager::getEntityPtr(index);
740 CWorldPositionManager::activateSelfSlot(entity);
741 #endif
744 /****************************************************************\
745 desactivate player self slot
746 \****************************************************************/
747 void cbDesactivateSelf( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
749 #ifdef HANDLE_SLOT0_SPECIAL
750 CEntityId id;
752 msgin.serial(id);
754 TDataSetRow index = CWorldPositionManager::getEntityIndex(id);
755 CWorldEntity *entity = CWorldPositionManager::getEntityPtr(index);
756 CWorldPositionManager::desactivateSelfSlot(entity);
757 #endif
760 // The following removed by Sadge because the entity has been removed from the mirror by the time the message arrives,
761 // making it redundant
762 ///****************************************************************\
763 // disable vision processing
764 //\****************************************************************/
765 //void cbDisableVisionProcessing( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
767 // CEntityId id;
769 // msgin.serial(id);
771 // TDataSetRow index = CWorldPositionManager::getEntityIndex(id);
772 // CWorldPositionManager::setPlayerVisionProcessing(index, false);
776 /****************************************************************\
777 Subscribe to a trigger
778 \****************************************************************/
779 void cbTriggerSubscribe( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
781 while ((uint32)msgin.getPos() < msgin.length())
783 string name;
784 uint16 id;
785 msgin.serial(name, id);
786 CWorldPositionManager::triggerSubscribe(serviceId, name, id);
790 /****************************************************************\
791 Unsubscribe to a trigger
792 \****************************************************************/
793 void cbTriggerUnsubscribe( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
795 while ((uint32)msgin.getPos() < msgin.length())
797 uint16 id;
798 msgin.serial(id);
799 CWorldPositionManager::triggerUnsubscribe(serviceId, id);
804 /****************************************************************\
805 request all entities arround an entity
806 \****************************************************************/
807 void cbEntitiesArroundEntity( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
809 CEntityId id; // base entity for decide list of entities arround this
810 list< string > propertySubscribe; // list of properties subscribe
812 msgin.serial( id );
813 msgin.serialCont( propertySubscribe );
815 CWorldPositionManager::requestForEntityAround( serviceId, id, propertySubscribe );
817 nlinfo("Service %s asked for local mirror around entity %s",serviceName.c_str(), id.toString().c_str() );
820 /****************************************************************\
821 end subscription for all entities arround an entity
822 \****************************************************************/
823 void cbEndEntitiesArroundEntity( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
825 CEntityId id; // base entity for decide list of entities arround this
827 msgin.serial( id );
829 CWorldPositionManager::unrequestForEntityAround( serviceId, id );
830 nlinfo("Service %s unsubscribe for local mirror around entity %s",serviceName.c_str(), id.toString().c_str() );
834 /****************************************************************\
835 ponctual vision request
836 \****************************************************************/
837 void cbVisionRequest( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
839 sint32 rid;
840 sint32 x, y;
841 sint32 range;
843 msgin.serial(rid, x, y, range);
845 static vector<pair<CEntityId, sint32> > entities;
846 entities.clear();
848 // get vision
849 CWorldPositionManager::visionRequest(x, y, range, entities);
851 // build vision answer
852 CMessage msgout("VISION_ANSWER");
853 msgout.serial(rid);
854 uint i;
855 const uint size = (uint)entities.size();
856 for ( i = 0 ; i < size ; ++i)
857 msgout.serial(entities[i].first, entities[i].second);
859 // send it to requester
860 sendMessageViaMirror(serviceId, msgout);
863 /****************************************************************\
864 ponctual vision request
865 \****************************************************************/
866 void cbR2ForceVisionReset( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
868 CEntityId eid;
870 msgin.serial(eid);
873 TDataSetRow entityIndex = TheDataset.getDataSetRow( eid );
874 BOMB_IF(!entityIndex.isValid() , "Try to reset the vision of a invalid player "+eid.toString(), return);
876 pCGPMS->RingVisionUniverse->forceResetVision(entityIndex);
883 //----------------------------
884 // CbArray
885 //----------------------------
886 TUnifiedCallbackItem CbGPMSArray[]=
888 // Callbacks for all service use GPMS
889 //{ "ADD_ENTITY", cbAddEntity }, // create a single entity
890 //{ "ADD_ENTITIES", cbAddEntities }, // create a set of entities
891 //{ "ADD_IA_OBJECT", cbAddIAObject }, // create an object only visible from ia agents
892 //{ "REPLACE_ENTITY", cbReplaceEntity}, // replace an entity by another entity
893 //{ "REMOVE_ENTITY", cbRemoveEntity }, // remove a single entity
894 //{ "REMOVE_ENTITIES", cbRemoveEntities }, // removes a set of entities
895 /*?DEAD?*/ { "BAG", cbBag }, // updates content of an entity (bag only ?)
897 /*?DEAD?*/ { "LOAD_CONTINENT", cbLoadContinent }, // load a continent
898 /*?DEAD?*/ { "REMOVE_CONTINENT", cbRemoveContinent }, // remove a continent
899 { "CREATE_INDOOR_UNIT", cbCreateIndoorUnit }, // create an indoor unit, for latter teleport
900 /*?DEAD?*/ { "CREATE_BUILDING", cbCreateBuilding }, // create a dynamic outdoor building
901 /*?DEAD?*/ { "CREATE_OBSTACLE", cbCreateObstacle }, // create a dynamic obstacle from a pacs_prim file
902 /*?DEAD?*/ { "REMOVE_OBSTACLE", cbRemoveObstacle }, // remove a dynamic obstacle
903 /*?DEAD?*/ { "SET_OBSTACLE", cbSetObstacle }, // set dynamic obstacle state
905 /*?DEAD?*/ { "TRIGGER_SUBSCRIBE", cbTriggerSubscribe },
906 /*?DEAD?*/ { "TRIGGER_UNSUBSCRIBE", cbTriggerUnsubscribe },
908 //{ "UPDATE_ENTITY_POS", cbUpdateEntityPosition}, // update a single entity position
909 //{ "UPDATE_ENTITIES_POSITIONS", cbUpdateEntitiesPositions}, // update a set of entities positions
910 //{ "UPDATE_ENTITIES_POS", cbUpdateEntitiesPositionsUsingSize }, // update a set of entities positions
911 { "ENTITY_TELEPORTATION", cbEntityTeleportation}, // teleport a single entity (if no position, remove from cell map)
913 /*?DEAD?*/ { "ATTACH", cbAttach }, // attach an entity (child) to an another (father) using direct local position
914 /*?DEAD?*/ { "DETACH", cbDetach }, // detach an entity of its father
915 { "SET_DEAD_STATUS", cbSetDeadStatus }, // entity acquire control of another entity
916 { "ACQUIRE_CONTROL", cbAcquireControl }, // entity acquire control of another entity
917 { "LEAVE_CONTROL", cbLeaveControl }, // entity leave control of another entity
919 /*?DEAD?*/ { "ACTIV_SELF", cbActivateSelf },
920 /*?DEAD?*/ { "DESACTIV_SELF", cbDesactivateSelf },
922 // The following removed by Sadge because the entity has been removed from the mirror by the time the message arrives,
923 // making it redundant
924 // / *?DEAD?* / { "DISABLE_VISION_PROC", cbDisableVisionProcessing }, // ask for player vision not to be updated any longer
926 /*?DEAD?*/ { "ENTITY_POS", cbEntityPosition }, // ask for position of an entity
928 /*?DEAD?*/ { "ASK_VISION_ARROUND_ENTITY", cbEntitiesArroundEntity }, // ask for vision update around an entity
929 /*?DEAD?*/ { "UNASK_VISION_ARROUND_ENTITY",cbEndEntitiesArroundEntity }, // remove vision update around an entity
931 /*?DEAD?*/ { "VISION_REQUEST", cbVisionRequest },
932 { "SET_PLAYER_FLAGS", cbSetPlayerFlags }, // set flags for player (limit speed, etc)
933 { "R2_VISION_REFRESH", cbR2ForceVisionReset }, // force the update of the vision (because some message must have been discared in Ring (in edition mode the network is not listen)
938 //-------------------------------------------------------------------------
939 // singleton initialisation and release
941 void CMessages::init()
943 // setup the callback array
944 CUnifiedNetwork::getInstance()->addCallbackArray( CbGPMSArray, sizeof(CbGPMSArray)/sizeof(CbGPMSArray[0]) );
947 void CMessages::release()