@@ -94,13 +94,18 @@ FString UPubnubSubsystem::GetUserID()
94
94
95
95
void UPubnubSubsystem::SetSecretKey ()
96
96
{
97
- if (!CheckIsPubnubInitialized () || ! CheckQuickActionThreadValidity () )
97
+ if (!CheckIsPubnubInitialized ())
98
98
{return ;}
99
99
100
- QuickActionThread-> AddFunctionToQueue ( [ this ]
100
+ if ( std::strlen (SecretKey) == 0 )
101
101
{
102
- SetSecretKey_priv ();
103
- });
102
+ PubnubError (" Can't set Secret Key. Secret Key is empty." );
103
+ return ;
104
+ }
105
+
106
+ // This function only changes data locally, doesn't do any networking operations, so no need to call it on separate thread
107
+ pubnub_set_secret_key (ctx_pub, SecretKey);
108
+ pubnub_set_secret_key (ctx_sub, SecretKey);
104
109
}
105
110
106
111
void UPubnubSubsystem::PublishMessage (FString Channel, FString Message, FPubnubPublishSettings PublishSettings)
@@ -349,11 +354,15 @@ void UPubnubSubsystem::SetAuthToken(FString Token)
349
354
{
350
355
if (!CheckIsPubnubInitialized () || !CheckQuickActionThreadValidity ())
351
356
{return ;}
352
-
353
- QuickActionThread->AddFunctionToQueue ( [this , Token]
354
- {
355
- SetAuthToken_priv (Token);
356
- });
357
+
358
+ if (!CheckIsUserIDSet ())
359
+ {return ;}
360
+
361
+ if (CheckIsFieldEmpty (Token, " Token" , " SetAuthToken" ))
362
+ {return ;}
363
+
364
+ // This is just a setter, so no need to call it on a separate thread
365
+ pubnub_set_auth_token (ctx_pub, TCHAR_TO_ANSI (*Token));
357
366
}
358
367
359
368
void UPubnubSubsystem::FetchHistory (FString Channel, FOnFetchHistoryResponse OnFetchHistoryResponse, FPubnubFetchHistorySettings FetchHistorySettings)
@@ -850,6 +859,9 @@ void UPubnubSubsystem::StartPubnubSubscribeLoop()
850
859
851
860
FString UPubnubSubsystem::StringArrayToCommaSeparated (TArray<FString> StringArray)
852
861
{
862
+ if (StringArray.IsEmpty ())
863
+ {return " " ;}
864
+
853
865
FString CommaSeparatedString;
854
866
for (FString StringElement : SubscribedChannels)
855
867
{
@@ -1070,13 +1082,12 @@ void UPubnubSubsystem::InitPubnub_priv()
1070
1082
1071
1083
pubnub_init (ctx_pub, PublishKey, SubscribeKey);
1072
1084
pubnub_init (ctx_sub, PublishKey, SubscribeKey);
1073
-
1085
+ IsInitialized = true ;
1086
+
1074
1087
if (PubnubSettings->SetSecretKeyAutomatically )
1075
1088
{
1076
1089
SetSecretKey ();
1077
1090
}
1078
-
1079
- IsInitialized = true ;
1080
1091
}
1081
1092
1082
1093
void UPubnubSubsystem::DeinitPubnub_priv ()
@@ -1116,18 +1127,6 @@ void UPubnubSubsystem::SetUserID_priv(FString UserID)
1116
1127
IsUserIDSet = true ;
1117
1128
}
1118
1129
1119
- void UPubnubSubsystem::SetSecretKey_priv ()
1120
- {
1121
- if (std::strlen (SecretKey) == 0 )
1122
- {
1123
- PubnubError (" Can't set Secret Key. Secret Key is empty." );
1124
- return ;
1125
- }
1126
-
1127
- pubnub_set_secret_key (ctx_pub, SecretKey);
1128
- pubnub_set_secret_key (ctx_sub, SecretKey);
1129
- }
1130
-
1131
1130
void UPubnubSubsystem::PublishMessage_priv (FString Channel, FString Message, FPubnubPublishSettings PublishSettings)
1132
1131
{
1133
1132
if (!CheckIsUserIDSet ())
@@ -1268,6 +1267,9 @@ void UPubnubSubsystem::UnsubscribeFromGroup_priv(FString GroupName)
1268
1267
1269
1268
void UPubnubSubsystem::UnsubscribeFromAll_priv ()
1270
1269
{
1270
+ if (SubscribedChannels.IsEmpty () && SubscribedGroups.IsEmpty ())
1271
+ {return ;}
1272
+
1271
1273
if (!CheckIsUserIDSet ())
1272
1274
{return ;}
1273
1275
@@ -1622,46 +1624,19 @@ void UPubnubSubsystem::ParseToken_priv(FString Token, FOnPubnubResponse OnParseT
1622
1624
if (CheckIsFieldEmpty (Token, " Token" , " ParseToken" ))
1623
1625
{return ;}
1624
1626
1625
- pubnub_parse_token (ctx_pub, TCHAR_TO_ANSI (*Token));
1626
-
1627
- pubnub_res PubnubResponse = pubnub_await (ctx_pub);
1628
- if (PubnubResponse != PNR_OK)
1629
- {
1630
- PubnubResponseError (PubnubResponse, " Failed to Parse Token." );
1631
- }
1632
-
1633
- pubnub_chamebl_t grant_token_resp = pubnub_get_grant_token (ctx_pub);
1634
- if (!grant_token_resp.ptr )
1635
- {
1636
- PubnubError (" Failed to get Parse Token - pointer to token is invalid." );
1637
- return ;
1638
- }
1627
+ char * TokenResponse = pubnub_parse_token (ctx_pub, TCHAR_TO_ANSI (*Token));
1639
1628
1640
- FString JsonResponse (grant_token_resp. ptr );
1629
+ FString JsonResponse (TokenResponse );
1641
1630
1642
1631
// Delegate needs to be executed back on Game Thread
1643
1632
AsyncTask (ENamedThreads::GameThread, [this , OnParseTokenResponse, JsonResponse]()
1644
1633
{
1645
1634
// Broadcast bound delegate with JsonResponse
1646
1635
OnParseTokenResponse.ExecuteIfBound (JsonResponse);
1647
1636
});
1648
- }
1649
-
1650
- void UPubnubSubsystem::SetAuthToken_priv (FString Token)
1651
- {
1652
- if (!CheckIsUserIDSet ())
1653
- {return ;}
1654
-
1655
- if (CheckIsFieldEmpty (Token, " Token" , " SetAuthToken" ))
1656
- {return ;}
1657
1637
1658
- pubnub_set_auth_token (ctx_pub, TCHAR_TO_ANSI (*Token));
1659
-
1660
- pubnub_res PubnubResponse = pubnub_await (ctx_pub);
1661
- if (PubnubResponse != PNR_OK)
1662
- {
1663
- PubnubResponseError (PubnubResponse, " Failed to Set Auth Token." );
1664
- }
1638
+ // Free this char, as it's allocated with malloc inside of pubnub_parse_token
1639
+ free (TokenResponse);
1665
1640
}
1666
1641
1667
1642
FString UPubnubSubsystem::FetchHistory_pn (FString Channel, FPubnubFetchHistorySettings FetchHistorySettings)
@@ -2520,6 +2495,7 @@ TSharedPtr<FJsonObject> UPubnubSubsystem::AddChannelPermissionsToJson(TArray<FSt
2520
2495
ChPerm.update = CurrentPermissions.Update ;
2521
2496
ChPerm.manage = CurrentPermissions.Manage ;
2522
2497
ChPerm.join = CurrentPermissions.Join ;
2498
+ ChPerm.create = false ;
2523
2499
int PermBitMask = pubnub_get_grant_bit_mask_value (ChPerm);
2524
2500
2525
2501
JsonObject->SetNumberField (Channels[i], PermBitMask);
@@ -2550,6 +2526,12 @@ TSharedPtr<FJsonObject> UPubnubSubsystem::AddChannelGroupPermissionsToJson(TArra
2550
2526
struct pam_permission ChPerm;
2551
2527
ChPerm.read = CurrentPermissions.Read ;
2552
2528
ChPerm.manage = CurrentPermissions.Manage ;
2529
+ ChPerm.write = false ;
2530
+ ChPerm.del = false ;
2531
+ ChPerm.get = false ;
2532
+ ChPerm.update = false ;
2533
+ ChPerm.join = false ;
2534
+ ChPerm.create = false ;
2553
2535
int PermBitMask = pubnub_get_grant_bit_mask_value (ChPerm);
2554
2536
2555
2537
JsonObject->SetNumberField (ChannelGroups[i], PermBitMask);
@@ -2581,6 +2563,11 @@ TSharedPtr<FJsonObject> UPubnubSubsystem::AddUserPermissionsToJson(TArray<FStrin
2581
2563
ChPerm.del = CurrentPermissions.Delete ;
2582
2564
ChPerm.get = CurrentPermissions.Get ;
2583
2565
ChPerm.update = CurrentPermissions.Update ;
2566
+ ChPerm.read = false ;
2567
+ ChPerm.write = false ;
2568
+ ChPerm.manage = false ;
2569
+ ChPerm.join = false ;
2570
+ ChPerm.create = false ;
2584
2571
int PermBitMask = pubnub_get_grant_bit_mask_value (ChPerm);
2585
2572
2586
2573
JsonObject->SetNumberField (Users[i], PermBitMask);
0 commit comments