public void JsonRpcDispatchNotify() { // setup var typeRegistry = new TypeRegistry(); var method = typeRegistry.RPCFunc((int a, int b) => a + b); var dispatcher = new RPCDispatcher(); dispatcher.AddNotifyMethod("Add", method); // notify var notify = "{\"jsonrpc\":\"2.0\",\"method\":\"Add\",\"params\":[1,2]}"; dispatcher.DispatchNotify(notify.ParseAsJson()); }
public void JsonRpcDispatchRequest() { // setup var typeRegistry = new TypeRegistry(); var method = typeRegistry.RPCFunc((int a, int b) => a + b); var dispatcher = new RPCDispatcher(); dispatcher.AddRequestMethod("Add", method); // request var request = "{\"jsonrpc\":\"2.0\",\"method\":\"Add\",\"params\":[1,2],\"id\":1}"; var response = Encoding.UTF8.GetString(dispatcher.DispatchRequest <Osaru.Json.JsonParser, Osaru.Json.JsonFormatter>(request.ParseAsJson()).ToEnumerable().ToArray()); Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":3,\"id\":1}", response); }
public void MsgPackRpcDispatchNotify() { // setup var typeRegistry = new TypeRegistry(); var method = typeRegistry.RPCFunc((int a, int b) => a + b); var dispatcher = new RPCDispatcher(); dispatcher.AddNotifyMethod("Add", method); // notify var notify = new RPCNotify <Osaru.MessagePack.MessagePackParser> { Method = "Add", ParamsBytes = typeRegistry.SerializeToMessagePack(new[] { 1, 2 }) }; dispatcher.DispatchNotify(notify); }
public void Intercept(ControllerManager controllerManager) { m_controllerManager = controllerManager; RPCDispatcher rpcDispatcher = controllerManager.Network.Net.RpcDispatcher; // initialize all Lists foreach (var evt in rpcDispatcher.Functions) { Events[evt.Key] = new List <EventListener>(); } // initialize custom struct lists Events[typeof(ClientConnected)] = new List <EventListener>(); Events[typeof(ClientDisconnected)] = new List <EventListener>(); // make a copy of the original events cFunctions = new Dictionary <Type, RPCDelegate>(rpcDispatcher.Functions); // hook my events in and call the old ones rpcDispatcher.Functions[typeof(ClientLogin)] = new RPCDelegate(OnPacketLogin); rpcDispatcher.Functions[typeof(ClientLoginAsGhost)] = new RPCDelegate(OnPacketLoginAsGhost); rpcDispatcher.Functions[typeof(ClientRespawn)] = new RPCDelegate(OnPacketRespawn); rpcDispatcher.Functions[typeof(ClientRequestSystViewData)] = new RPCDelegate(OnPacketRequestSystemViewData); rpcDispatcher.Functions[typeof(ClientChunkSaveData)] = new RPCDelegate(OnPacketClientSaveData); rpcDispatcher.Functions[typeof(ClientEntData)] = new RPCDelegate(OnPacketEntData); rpcDispatcher.Functions[typeof(ClientDeviceData)] = new RPCDelegate(OnPacketClientDeviceData); rpcDispatcher.Functions[typeof(ClientDeviceHelperData)] = new RPCDelegate(OnPacketDeviceHelperData); rpcDispatcher.Functions[typeof(ClientShipUpgradeData)] = new RPCDelegate(OnPacketShipUpgradeData); rpcDispatcher.Functions[typeof(ClientUserGroupsData)] = new RPCDelegate(OnPacketClientUserGroupData); rpcDispatcher.Functions[typeof(ClientPlayersOnShipData)] = new RPCDelegate(i_onPacketClientPlayersOnShipStatsData); rpcDispatcher.Functions[typeof(ClientGiveInventoryItemToPlayer)] = new RPCDelegate(OnPacketClientGiveInventoryItemToPlayer); rpcDispatcher.Functions[typeof(ClientPlayerToolData)] = new RPCDelegate(i_onPacketClientPlayerCommandData); rpcDispatcher.Functions[typeof(ClientPlayerState)] = new RPCDelegate(OnPacketClientStateSync); rpcDispatcher.Functions[typeof(ClientChatMessage)] = new RPCDelegate(OnPacketChatMessage); rpcDispatcher.Functions[typeof(ClientMailMessage)] = new RPCDelegate(OnPacketMailMessage); rpcDispatcher.Functions[typeof(ClientRemoveMail)] = new RPCDelegate(OnPacketRemoveMail); rpcDispatcher.Functions[typeof(ClientMailChangeReadState)] = new RPCDelegate(OnPacketMailChangeReadState); rpcDispatcher.Functions[typeof(ClientAcceptFleetInvite)] = new RPCDelegate(OnPacketAcceptFleetInvite); rpcDispatcher.Functions[typeof(ClientCreateFleet)] = new RPCDelegate(OnPacketCreateFleet); rpcDispatcher.Functions[typeof(ClientRemoveFleetMember)] = new RPCDelegate(OnPacketRemoveFactionMember); rpcDispatcher.Functions[typeof(ClientCreateFleetRank)] = new RPCDelegate(OnPacketCreateFactionRank); rpcDispatcher.Functions[typeof(ClientRemoveFleetRank)] = new RPCDelegate(OnPacketRemoveFactionRank); rpcDispatcher.Functions[typeof(ClientEditFleetRank)] = new RPCDelegate(OnPacketEditFactionRank); rpcDispatcher.Functions[typeof(ClientReorderFleetRank)] = new RPCDelegate(OnPacketReorderFactionRank); rpcDispatcher.Functions[typeof(ClientChangeMemberRank)] = new RPCDelegate(OnPacketChangeMemberRank); rpcDispatcher.Functions[typeof(ClientDisbandFleet)] = new RPCDelegate(OnPacketDisbandFaction); rpcDispatcher.Functions[typeof(ClientLeaveFleet)] = new RPCDelegate(OnPacketLeaveFaction); rpcDispatcher.Functions[typeof(ClientPayFactionBounty)] = new RPCDelegate(OnPacketPayNPCFactionBounty); rpcDispatcher.Functions[typeof(ClientCreateCrew)] = new RPCDelegate(OnPacketCreateCrew); rpcDispatcher.Functions[typeof(ClientAcceptCrewInvite)] = new RPCDelegate(OnPacketAcceptCrewInvite); rpcDispatcher.Functions[typeof(ClientLeaveCrew)] = new RPCDelegate(OnPacketLeaveCrew); rpcDispatcher.Functions[typeof(ClientPayFine)] = new RPCDelegate(OnPacketPayFine); rpcDispatcher.Functions[typeof(ClientPayAllFines)] = new RPCDelegate(i_onPacketPayAllFines); rpcDispatcher.Functions[typeof(ClientKickCrewMember)] = new RPCDelegate(OnPacketKickCrewMember); rpcDispatcher.Functions[typeof(ClientDisbandCrew)] = new RPCDelegate(OnPacketDisbandCrew); rpcDispatcher.Functions[typeof(ClientAdminCommand)] = new RPCDelegate(OnPacketAdminCommand); rpcDispatcher.Functions[typeof(ClientSelectStartFaction)] = new RPCDelegate(OnPacketSelectStartFaction); rpcDispatcher.Functions[typeof(ClientAbandonMission)] = new RPCDelegate(OnPacketAbandonMission); rpcDispatcher.Functions[typeof(ClientProjectileHit)] = new RPCDelegate(OnPacketProjectileHit); rpcDispatcher.Functions[typeof(ClientAddProjectile)] = new RPCDelegate(OnPacketAddProjectile); rpcDispatcher.Functions[typeof(ClientRemoveProjectile)] = new RPCDelegate(OnPacketRemoveProjectile); rpcDispatcher.Functions[typeof(ClientProjectileSyncData)] = new RPCDelegate(OnPacketProjectileSyncData); rpcDispatcher.Functions[typeof(ClientProjectileSpawnData)] = new RPCDelegate(OnPacketProjectileSpawnData); rpcDispatcher.Functions[typeof(ClientNotifyDesync)] = new RPCDelegate(OnPacketNotifyDesync); rpcDispatcher.Functions[typeof(ClientNetStats)] = new RPCDelegate(OnPacketNetStats); rpcDispatcher.Functions[typeof(ClientNetTrack)] = new RPCDelegate(OnPacketNetTrack); rpcDispatcher.Functions[typeof(ClientUnequipPlayerEquipment)] = new RPCDelegate(OnPacketUnequipPlayerEquipment); rpcDispatcher.Functions[typeof(ClientRequestShipDelivery)] = new RPCDelegate(OnPacketRequestShipDelivery); rpcDispatcher.Functions[typeof(ClientRequestSystemMetadata)] = new RPCDelegate(OnPacketRequestSystemMetadata); rpcDispatcher.Functions[typeof(ClientChangeCaptainsTask)] = new RPCDelegate(OnPacketChangeCaptainsTask); rpcDispatcher.Functions[typeof(ClientCompleteMissionObjective)] = new RPCDelegate(OnPacketCompleteMissionObjective); rpcDispatcher.Functions[typeof(ClientVariableEdit)] = new RPCDelegate(i_onPacketVariableEdit); rpcDispatcher.Functions[typeof(ClientSpawnEntity)] = new RPCDelegate(i_onPacketSpawnEntity); rpcDispatcher.Functions[typeof(ClientClaimRewardsForProgressionItem)] = new RPCDelegate(OnPacketClaimProgressionReward); rpcDispatcher.Functions[typeof(GhostClientHeartbeat)] = new RPCDelegate(i_onPacketGhostClientHeartbeat); rpcDispatcher.Functions[typeof(GhostClientRequestChunkSaveDataAcknowledge)] = new RPCDelegate(i_onPacketGhostClientRequestChunkSaveDataAcknowledge); rpcDispatcher.Functions[typeof(ClientChangeActiveMission)] = new RPCDelegate(OnPacketChangeActiveMission); rpcDispatcher.Functions[typeof(ClientSetShipPurchasable)] = new RPCDelegate(OnPacketSetShipPurchasable); rpcDispatcher.Functions[typeof(ClientPurchaseShip)] = new RPCDelegate(OnPacketPurchaseShip); rpcDispatcher.Functions[typeof(ClientSetShipName)] = new RPCDelegate(OnPacketSetShipName); rpcDispatcher.Functions[typeof(ClientSplitStack)] = new RPCDelegate(OnPacketSplitStack); controllerManager.Players.OnAddPlayer += new Action <Player>(Players_OnAddPlayer); controllerManager.Players.OnRemovePlayer += new Action <Player>(Players_OnRemovePlayer); }
public void Initialize(RPCDispatcher dispatcher) { dispatcher.Functions[typeof(HelloWorldPacket)] = OnPacketHelloWorld; dispatcher.Functions[typeof(RequestPlayerCharacterClientPacket)] = OnPacketRequestPlayerCharacter; dispatcher.Functions[typeof(CharacterUpdateClientPacket)] = OnPacketCharacterUpdate; }
public void Initialize(RPCDispatcher dispatcher) { dispatcher.Functions[typeof(HelloWorldPacket)] = OnPacketHelloWorld; dispatcher.Functions[typeof(SpawnPlayerServerPacket)] = OnSpawnPlayerServerPacket; dispatcher.Functions[typeof(ServerUpdatePacket)] = OnServerUpdatePacket; }