RPC3.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "RPC3.h"
  11. #include "RakMemoryOverride.h"
  12. #include "RakAssert.h"
  13. #include "StringCompressor.h"
  14. #include "BitStream.h"
  15. #include "RakPeerInterface.h"
  16. #include "MessageIdentifiers.h"
  17. #include "NetworkIDManager.h"
  18. #include <stdlib.h>
  19. using namespace RakNet;
  20. // int RPC3::RemoteRPCFunctionComp( const RPC3::RPCIdentifier &key, const RemoteRPCFunction &data )
  21. // {
  22. // return strcmp(key.C_String(), data.identifier.C_String());
  23. // }
  24. int RakNet::RPC3::LocalSlotObjectComp( const LocalSlotObject &key, const LocalSlotObject &data )
  25. {
  26. if (key.callPriority>data.callPriority)
  27. return -1;
  28. if (key.callPriority==data.callPriority)
  29. {
  30. if (key.registrationCount<data.registrationCount)
  31. return -1;
  32. if (key.registrationCount==data.registrationCount)
  33. return 0;
  34. return 1;
  35. }
  36. return 1;
  37. }
  38. RPC3::RPC3()
  39. {
  40. currentExecution[0]=0;
  41. networkIdManager=0;
  42. outgoingTimestamp=0;
  43. outgoingPriority=HIGH_PRIORITY;
  44. outgoingReliability=RELIABLE_ORDERED;
  45. outgoingOrderingChannel=0;
  46. outgoingBroadcast=true;
  47. incomingTimeStamp=0;
  48. nextSlotRegistrationCount=0;
  49. }
  50. RPC3::~RPC3()
  51. {
  52. Clear();
  53. }
  54. void RPC3::SetNetworkIDManager(NetworkIDManager *idMan)
  55. {
  56. networkIdManager=idMan;
  57. }
  58. bool RPC3::UnregisterFunction(const char *uniqueIdentifier)
  59. {
  60. return false;
  61. }
  62. bool RPC3::IsFunctionRegistered(const char *uniqueIdentifier)
  63. {
  64. DataStructures::HashIndex i = GetLocalFunctionIndex(uniqueIdentifier);
  65. return i.IsInvalid()==false;
  66. }
  67. void RPC3::SetTimestamp(RakNet::Time timeStamp)
  68. {
  69. outgoingTimestamp=timeStamp;
  70. }
  71. void RPC3::SetSendParams(PacketPriority priority, PacketReliability reliability, char orderingChannel)
  72. {
  73. outgoingPriority=priority;
  74. outgoingReliability=reliability;
  75. outgoingOrderingChannel=orderingChannel;
  76. }
  77. void RPC3::SetRecipientAddress(const SystemAddress &systemAddress, bool broadcast)
  78. {
  79. outgoingSystemAddress=systemAddress;
  80. outgoingBroadcast=broadcast;
  81. }
  82. void RPC3::SetRecipientObject(NetworkID networkID)
  83. {
  84. outgoingNetworkID=networkID;
  85. }
  86. RakNet::Time RPC3::GetLastSenderTimestamp(void) const
  87. {
  88. return incomingTimeStamp;
  89. }
  90. SystemAddress RPC3::GetLastSenderAddress(void) const
  91. {
  92. return incomingSystemAddress;
  93. }
  94. RakPeerInterface *RPC3::GetRakPeer(void) const
  95. {
  96. return rakPeerInterface;
  97. }
  98. const char *RPC3::GetCurrentExecution(void) const
  99. {
  100. return (const char *) currentExecution;
  101. }
  102. bool RPC3::SendCallOrSignal(RakString uniqueIdentifier, char parameterCount, RakNet::BitStream *serializedParameters, bool isCall)
  103. {
  104. SystemAddress systemAddr;
  105. // unsigned int outerIndex;
  106. // unsigned int innerIndex;
  107. if (uniqueIdentifier.IsEmpty())
  108. return false;
  109. RakNet::BitStream bs;
  110. if (outgoingTimestamp!=0)
  111. {
  112. bs.Write((MessageID)ID_TIMESTAMP);
  113. bs.Write(outgoingTimestamp);
  114. }
  115. bs.Write((MessageID)ID_RPC_PLUGIN);
  116. bs.Write(parameterCount);
  117. if (outgoingNetworkID!=UNASSIGNED_NETWORK_ID && isCall)
  118. {
  119. bs.Write(true);
  120. bs.Write(outgoingNetworkID);
  121. }
  122. else
  123. {
  124. bs.Write(false);
  125. }
  126. bs.Write(isCall);
  127. // This is so the call SetWriteOffset works
  128. bs.AlignWriteToByteBoundary();
  129. BitSize_t writeOffset = bs.GetWriteOffset();
  130. if (outgoingBroadcast)
  131. {
  132. unsigned systemIndex;
  133. for (systemIndex=0; systemIndex < rakPeerInterface->GetMaximumNumberOfPeers(); systemIndex++)
  134. {
  135. systemAddr=rakPeerInterface->GetSystemAddressFromIndex(systemIndex);
  136. if (systemAddr!=RakNet::UNASSIGNED_SYSTEM_ADDRESS && systemAddr!=outgoingSystemAddress)
  137. {
  138. // if (GetRemoteFunctionIndex(systemAddr, uniqueIdentifier, &outerIndex, &innerIndex, isCall))
  139. // {
  140. // // Write a number to identify the function if possible, for faster lookup and less bandwidth
  141. // bs.Write(true);
  142. // if (isCall)
  143. // bs.WriteCompressed(remoteFunctions[outerIndex]->operator [](innerIndex).functionIndex);
  144. // else
  145. // bs.WriteCompressed(remoteSlots[outerIndex]->operator [](innerIndex).functionIndex);
  146. // }
  147. // else
  148. // {
  149. // bs.Write(false);
  150. StringCompressor::Instance()->EncodeString(uniqueIdentifier, 512, &bs, 0);
  151. // }
  152. bs.WriteCompressed(serializedParameters->GetNumberOfBitsUsed());
  153. // serializedParameters->PrintBits();
  154. bs.WriteAlignedBytes((const unsigned char*) serializedParameters->GetData(), serializedParameters->GetNumberOfBytesUsed());
  155. SendUnified(&bs, outgoingPriority, outgoingReliability, outgoingOrderingChannel, systemAddr, false);
  156. // Start writing again after ID_AUTO_RPC_CALL
  157. bs.SetWriteOffset(writeOffset);
  158. }
  159. }
  160. }
  161. else
  162. {
  163. systemAddr = outgoingSystemAddress;
  164. if (systemAddr!=RakNet::UNASSIGNED_SYSTEM_ADDRESS)
  165. {
  166. // if (GetRemoteFunctionIndex(systemAddr, uniqueIdentifier, &outerIndex, &innerIndex, isCall))
  167. // {
  168. // // Write a number to identify the function if possible, for faster lookup and less bandwidth
  169. // bs.Write(true);
  170. // if (isCall)
  171. // bs.WriteCompressed(remoteFunctions[outerIndex]->operator [](innerIndex).functionIndex);
  172. // else
  173. // bs.WriteCompressed(remoteSlots[outerIndex]->operator [](innerIndex).functionIndex);
  174. // }
  175. // else
  176. // {
  177. // bs.Write(false);
  178. StringCompressor::Instance()->EncodeString(uniqueIdentifier, 512, &bs, 0);
  179. // }
  180. bs.WriteCompressed(serializedParameters->GetNumberOfBitsUsed());
  181. bs.WriteAlignedBytes((const unsigned char*) serializedParameters->GetData(), serializedParameters->GetNumberOfBytesUsed());
  182. SendUnified(&bs, outgoingPriority, outgoingReliability, outgoingOrderingChannel, systemAddr, false);
  183. }
  184. else
  185. return false;
  186. }
  187. return true;
  188. }
  189. void RPC3::OnAttach(void)
  190. {
  191. outgoingSystemAddress=RakNet::UNASSIGNED_SYSTEM_ADDRESS;
  192. outgoingNetworkID=UNASSIGNED_NETWORK_ID;
  193. incomingSystemAddress=RakNet::UNASSIGNED_SYSTEM_ADDRESS;
  194. }
  195. PluginReceiveResult RPC3::OnReceive(Packet *packet)
  196. {
  197. RakNet::Time timestamp=0;
  198. unsigned char packetIdentifier, packetDataOffset;
  199. if ( ( unsigned char ) packet->data[ 0 ] == ID_TIMESTAMP )
  200. {
  201. if ( packet->length > sizeof( unsigned char ) + sizeof( RakNet::Time ) )
  202. {
  203. packetIdentifier = ( unsigned char ) packet->data[ sizeof( unsigned char ) + sizeof( RakNet::Time ) ];
  204. // Required for proper endian swapping
  205. RakNet::BitStream tsBs(packet->data+sizeof(MessageID),packet->length-1,false);
  206. tsBs.Read(timestamp);
  207. packetDataOffset=sizeof( unsigned char )*2 + sizeof( RakNet::Time );
  208. }
  209. else
  210. return RR_STOP_PROCESSING_AND_DEALLOCATE;
  211. }
  212. else
  213. {
  214. packetIdentifier = ( unsigned char ) packet->data[ 0 ];
  215. packetDataOffset=sizeof( unsigned char );
  216. }
  217. switch (packetIdentifier)
  218. {
  219. case ID_RPC_PLUGIN:
  220. incomingTimeStamp=timestamp;
  221. incomingSystemAddress=packet->systemAddress;
  222. OnRPC3Call(packet->systemAddress, packet->data+packetDataOffset, packet->length-packetDataOffset);
  223. return RR_STOP_PROCESSING_AND_DEALLOCATE;
  224. // case ID_AUTO_RPC_REMOTE_INDEX:
  225. // OnRPCRemoteIndex(packet->systemAddress, packet->data+packetDataOffset, packet->length-packetDataOffset);
  226. // return RR_STOP_PROCESSING_AND_DEALLOCATE;
  227. }
  228. return RR_CONTINUE_PROCESSING;
  229. }
  230. void RPC3::OnRPC3Call(const SystemAddress &systemAddress, unsigned char *data, unsigned int lengthInBytes)
  231. {
  232. RakNet::BitStream bs(data,lengthInBytes,false);
  233. DataStructures::HashIndex functionIndex;
  234. LocalRPCFunction *lrpcf;
  235. bool hasParameterCount=false;
  236. char parameterCount;
  237. NetworkIDObject *networkIdObject;
  238. NetworkID networkId;
  239. bool hasNetworkId=false;
  240. // bool hasFunctionIndex=false;
  241. // unsigned int functionIndex;
  242. BitSize_t bitsOnStack;
  243. char strIdentifier[512];
  244. incomingExtraData.Reset();
  245. bs.Read(parameterCount);
  246. bs.Read(hasNetworkId);
  247. if (hasNetworkId)
  248. {
  249. bool readSuccess = bs.Read(networkId);
  250. RakAssert(readSuccess);
  251. RakAssert(networkId!=UNASSIGNED_NETWORK_ID);
  252. if (networkIdManager==0)
  253. {
  254. // Failed - Tried to call object member, however, networkIDManager system was never registered
  255. SendError(systemAddress, RPC_ERROR_NETWORK_ID_MANAGER_UNAVAILABLE, "");
  256. return;
  257. }
  258. networkIdObject = networkIdManager->GET_OBJECT_FROM_ID<NetworkIDObject*>(networkId);
  259. if (networkIdObject==0)
  260. {
  261. // Failed - Tried to call object member, object does not exist (deleted?)
  262. SendError(systemAddress, RPC_ERROR_OBJECT_DOES_NOT_EXIST, "");
  263. return;
  264. }
  265. }
  266. else
  267. {
  268. networkIdObject=0;
  269. }
  270. bool isCall;
  271. bs.Read(isCall);
  272. bs.AlignReadToByteBoundary();
  273. // bs.Read(hasFunctionIndex);
  274. // if (hasFunctionIndex)
  275. // bs.ReadCompressed(functionIndex);
  276. // else
  277. StringCompressor::Instance()->DecodeString(strIdentifier,512,&bs,0);
  278. bs.ReadCompressed(bitsOnStack);
  279. RakNet::BitStream serializedParameters;
  280. if (bitsOnStack>0)
  281. {
  282. serializedParameters.AddBitsAndReallocate(bitsOnStack);
  283. // BITS_TO_BYTES is correct, why did I change this?
  284. bs.ReadAlignedBytes(serializedParameters.GetData(), BITS_TO_BYTES(bitsOnStack));
  285. serializedParameters.SetWriteOffset(bitsOnStack);
  286. }
  287. // if (hasFunctionIndex)
  288. // {
  289. // if (
  290. // (isCall==true && functionIndex>localFunctions.Size()) ||
  291. // (isCall==false && functionIndex>localSlots.Size())
  292. // )
  293. // {
  294. // // Failed - other system specified a totally invalid index
  295. // // Possible causes: Bugs, attempts to crash the system, requested function not registered
  296. // SendError(systemAddress, RPC_ERROR_FUNCTION_INDEX_OUT_OF_RANGE, "");
  297. // return;
  298. // }
  299. // }
  300. // else
  301. {
  302. // Find the registered function with this str
  303. if (isCall)
  304. {
  305. // for (functionIndex=0; functionIndex < localFunctions.Size(); functionIndex++)
  306. // {
  307. // bool isObjectMember = boost::fusion::get<0>(localFunctions[functionIndex].functionPointer);
  308. // // boost::function<_RPC3::InvokeResultCodes (_RPC3::InvokeArgs)> functionPtr = boost::fusion::get<0>(localFunctions[functionIndex].functionPointer);
  309. //
  310. // if (isObjectMember == (networkIdObject!=0) &&
  311. // strcmp(localFunctions[functionIndex].identifier.C_String(), strIdentifier)==0)
  312. // {
  313. // // SEND RPC MAPPING
  314. // RakNet::BitStream outgoingBitstream;
  315. // outgoingBitstream.Write((MessageID)ID_AUTO_RPC_REMOTE_INDEX);
  316. // outgoingBitstream.Write(hasNetworkId);
  317. // outgoingBitstream.WriteCompressed(functionIndex);
  318. // StringCompressor::Instance()->EncodeString(strIdentifier,512,&outgoingBitstream,0);
  319. // outgoingBitstream.Write(isCall);
  320. // SendUnified(&outgoingBitstream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, systemAddress, false);
  321. // break;
  322. // }
  323. // }
  324. functionIndex = localFunctions.GetIndexOf(strIdentifier);
  325. if (functionIndex.IsInvalid())
  326. {
  327. SendError(systemAddress, RPC_ERROR_FUNCTION_NOT_REGISTERED, strIdentifier);
  328. return;
  329. }
  330. lrpcf = localFunctions.ItemAtIndex(functionIndex);
  331. bool isObjectMember = boost::fusion::get<0>(lrpcf->functionPointer);
  332. if (isObjectMember==true && networkIdObject==0)
  333. {
  334. // Failed - Calling C++ function as C function
  335. SendError(systemAddress, RPC_ERROR_CALLING_CPP_AS_C, strIdentifier);
  336. return;
  337. }
  338. if (isObjectMember==false && networkIdObject!=0)
  339. {
  340. // Failed - Calling C function as C++ function
  341. SendError(systemAddress, RPC_ERROR_CALLING_C_AS_CPP, strIdentifier);
  342. return;
  343. }
  344. }
  345. else
  346. {
  347. functionIndex = localSlots.GetIndexOf(strIdentifier);
  348. if (functionIndex.IsInvalid())
  349. {
  350. SendError(systemAddress, RPC_ERROR_FUNCTION_NOT_REGISTERED, strIdentifier);
  351. return;
  352. }
  353. }
  354. }
  355. if (isCall)
  356. {
  357. bool isObjectMember = boost::fusion::get<0>(lrpcf->functionPointer);
  358. boost::function<_RPC3::InvokeResultCodes (_RPC3::InvokeArgs)> functionPtr = boost::fusion::get<1>(lrpcf->functionPointer);
  359. // int arity = boost::fusion::get<2>(localFunctions[functionIndex].functionPointer);
  360. // if (isObjectMember)
  361. // arity--; // this pointer
  362. if (functionPtr==0)
  363. {
  364. // Failed - Function was previously registered, but isn't registered any longer
  365. SendError(systemAddress, RPC_ERROR_FUNCTION_NO_LONGER_REGISTERED, strIdentifier);
  366. return;
  367. }
  368. // Boost doesn't support this for class members
  369. // if (arity!=parameterCount)
  370. // {
  371. // // Failed - The number of parameters that this function has was explicitly specified, and does not match up.
  372. // SendError(systemAddress, RPC_ERROR_INCORRECT_NUMBER_OF_PARAMETERS, localFunctions[functionIndex].identifier);
  373. // return;
  374. // }
  375. _RPC3::InvokeArgs functionArgs;
  376. functionArgs.bitStream=&serializedParameters;
  377. functionArgs.networkIDManager=networkIdManager;
  378. functionArgs.caller=this;
  379. functionArgs.thisPtr=networkIdObject;
  380. // serializedParameters.PrintBits();
  381. _RPC3::InvokeResultCodes res2 = functionPtr(functionArgs);
  382. }
  383. else
  384. {
  385. InvokeSignal(functionIndex, &serializedParameters, false);
  386. }
  387. }
  388. void RPC3::InterruptSignal(void)
  389. {
  390. interruptSignal=true;
  391. }
  392. void RPC3::InvokeSignal(DataStructures::HashIndex functionIndex, RakNet::BitStream *serializedParameters, bool temporarilySetUSA)
  393. {
  394. if (functionIndex.IsInvalid())
  395. return;
  396. SystemAddress lastIncomingAddress=incomingSystemAddress;
  397. if (temporarilySetUSA)
  398. incomingSystemAddress=RakNet::UNASSIGNED_SYSTEM_ADDRESS;
  399. interruptSignal=false;
  400. LocalSlot *localSlot = localSlots.ItemAtIndex(functionIndex);
  401. unsigned int i;
  402. _RPC3::InvokeArgs functionArgs;
  403. functionArgs.bitStream=serializedParameters;
  404. functionArgs.networkIDManager=networkIdManager;
  405. functionArgs.caller=this;
  406. i=0;
  407. while (i < localSlot->slotObjects.Size())
  408. {
  409. if (localSlot->slotObjects[i].associatedObject!=UNASSIGNED_NETWORK_ID)
  410. {
  411. functionArgs.thisPtr = networkIdManager->GET_OBJECT_FROM_ID<NetworkIDObject*>(localSlot->slotObjects[i].associatedObject);
  412. if (functionArgs.thisPtr==0)
  413. {
  414. localSlot->slotObjects.RemoveAtIndex(i);
  415. continue;
  416. }
  417. }
  418. else
  419. functionArgs.thisPtr=0;
  420. functionArgs.bitStream->ResetReadPointer();
  421. bool isObjectMember = boost::fusion::get<0>(localSlot->slotObjects[i].functionPointer);
  422. boost::function<_RPC3::InvokeResultCodes (_RPC3::InvokeArgs)> functionPtr = boost::fusion::get<1>(localSlot->slotObjects[i].functionPointer);
  423. if (functionPtr==0)
  424. {
  425. if (temporarilySetUSA==false)
  426. {
  427. // Failed - Function was previously registered, but isn't registered any longer
  428. SendError(lastIncomingAddress, RPC_ERROR_FUNCTION_NO_LONGER_REGISTERED, localSlots.KeyAtIndex(functionIndex).C_String());
  429. }
  430. return;
  431. }
  432. _RPC3::InvokeResultCodes res2 = functionPtr(functionArgs);
  433. // Not threadsafe
  434. if (interruptSignal==true)
  435. break;
  436. i++;
  437. }
  438. if (temporarilySetUSA)
  439. incomingSystemAddress=lastIncomingAddress;
  440. }
  441. // void RPC3::OnRPCRemoteIndex(const SystemAddress &systemAddress, unsigned char *data, unsigned int lengthInBytes)
  442. // {
  443. // // A remote system has given us their internal index for a particular function.
  444. // // Store it and use it from now on, to save bandwidth and search time
  445. // bool objectExists;
  446. // RakString strIdentifier;
  447. // unsigned int insertionIndex;
  448. // unsigned int remoteIndex;
  449. // RemoteRPCFunction newRemoteFunction;
  450. // RakNet::BitStream bs(data,lengthInBytes,false);
  451. // RPCIdentifier identifier;
  452. // bool isObjectMember;
  453. // bool isCall;
  454. // bs.Read(isObjectMember);
  455. // bs.ReadCompressed(remoteIndex);
  456. // bs.Read(strIdentifier);
  457. // bs.Read(isCall);
  458. //
  459. // if (strIdentifier.IsEmpty())
  460. // return;
  461. //
  462. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList;
  463. // if (
  464. // (isCall==true && remoteFunctions.Has(systemAddress)) ||
  465. // (isCall==false && remoteSlots.Has(systemAddress))
  466. // )
  467. // {
  468. // if (isCall==true)
  469. // theList = remoteFunctions.Get(systemAddress);
  470. // else
  471. // theList = remoteSlots.Get(systemAddress);
  472. // insertionIndex=theList->GetIndexFromKey(identifier, &objectExists);
  473. // if (objectExists==false)
  474. // {
  475. // newRemoteFunction.functionIndex=remoteIndex;
  476. // newRemoteFunction.identifier = strIdentifier;
  477. // theList->InsertAtIndex(newRemoteFunction, insertionIndex, _FILE_AND_LINE_ );
  478. // }
  479. // }
  480. // else
  481. // {
  482. // theList = RakNet::OP_NEW<DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> >(_FILE_AND_LINE_);
  483. //
  484. // newRemoteFunction.functionIndex=remoteIndex;
  485. // newRemoteFunction.identifier = strIdentifier;
  486. // theList->InsertAtEnd(newRemoteFunction, _FILE_AND_LINE_ );
  487. //
  488. // if (isCall==true)
  489. // remoteFunctions.SetNew(systemAddress,theList);
  490. // else
  491. // remoteSlots.SetNew(systemAddress,theList);
  492. // }
  493. // }
  494. void RPC3::OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason )
  495. {
  496. // if (remoteFunctions.Has(systemAddress))
  497. // {
  498. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList = remoteFunctions.Get(systemAddress);
  499. // delete theList;
  500. // remoteFunctions.Delete(systemAddress);
  501. // }
  502. //
  503. // if (remoteSlots.Has(systemAddress))
  504. // {
  505. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList = remoteSlots.Get(systemAddress);
  506. // delete theList;
  507. // remoteSlots.Delete(systemAddress);
  508. // }
  509. }
  510. void RPC3::OnShutdown(void)
  511. {
  512. // Not needed, and if the user calls Shutdown inadvertantly, it unregisters his functions
  513. // Clear();
  514. }
  515. void RPC3::Clear(void)
  516. {
  517. unsigned j;
  518. // for (j=0; j < remoteFunctions.Size(); j++)
  519. // {
  520. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList = remoteFunctions[j];
  521. // RakNet::OP_DELETE(theList,_FILE_AND_LINE_);
  522. // }
  523. // for (j=0; j < remoteSlots.Size(); j++)
  524. // {
  525. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList = remoteSlots[j];
  526. // RakNet::OP_DELETE(theList,_FILE_AND_LINE_);
  527. // }
  528. DataStructures::List<RakNet::RakString> keyList;
  529. DataStructures::List<LocalSlot*> outputList;
  530. localSlots.GetAsList(outputList,keyList,_FILE_AND_LINE_);
  531. for (j=0; j < outputList.Size(); j++)
  532. {
  533. RakNet::OP_DELETE(outputList[j],_FILE_AND_LINE_);
  534. }
  535. localSlots.Clear(_FILE_AND_LINE_);
  536. DataStructures::List<LocalRPCFunction*> outputList2;
  537. localFunctions.GetAsList(outputList2,keyList,_FILE_AND_LINE_);
  538. for (j=0; j < outputList2.Size(); j++)
  539. {
  540. RakNet::OP_DELETE(outputList2[j],_FILE_AND_LINE_);
  541. }
  542. localFunctions.Clear(_FILE_AND_LINE_);
  543. // remoteFunctions.Clear();
  544. // remoteSlots.Clear();
  545. outgoingExtraData.Reset();
  546. incomingExtraData.Reset();
  547. }
  548. void RPC3::SendError(SystemAddress target, unsigned char errorCode, const char *functionName)
  549. {
  550. RakNet::BitStream bs;
  551. bs.Write((MessageID)ID_RPC_REMOTE_ERROR);
  552. bs.Write(errorCode);
  553. bs.WriteAlignedBytes((const unsigned char*) functionName,(const unsigned int) strlen(functionName)+1);
  554. SendUnified(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, target, false);
  555. }
  556. // bool RPC3::GetRemoteFunctionIndex(const SystemAddress &systemAddress, RPC3::RPCIdentifier identifier, unsigned int *outerIndex, unsigned int *innerIndex, bool isCall)
  557. // {
  558. // bool objectExists=false;
  559. // if (isCall)
  560. // {
  561. // if (remoteFunctions.Has(systemAddress))
  562. // {
  563. // *outerIndex = remoteFunctions.GetIndexAtKey(systemAddress);
  564. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList = remoteFunctions[*outerIndex];
  565. // *innerIndex = theList->GetIndexFromKey(identifier, &objectExists);
  566. // }
  567. // }
  568. // else
  569. // {
  570. // if (remoteSlots.Has(systemAddress))
  571. // {
  572. // *outerIndex = remoteFunctions.GetIndexAtKey(systemAddress);
  573. // DataStructures::OrderedList<RPCIdentifier, RemoteRPCFunction, RPC3::RemoteRPCFunctionComp> *theList = remoteSlots[*outerIndex];
  574. // *innerIndex = theList->GetIndexFromKey(identifier, &objectExists);
  575. // }
  576. // }
  577. // return objectExists;
  578. // }
  579. DataStructures::HashIndex RPC3::GetLocalSlotIndex(const char *sharedIdentifier)
  580. {
  581. return localSlots.GetIndexOf(sharedIdentifier);
  582. }
  583. DataStructures::HashIndex RPC3::GetLocalFunctionIndex(RPC3::RPCIdentifier identifier)
  584. {
  585. return localFunctions.GetIndexOf(identifier.C_String());
  586. }
粤ICP备19079148号