ChatOperationCode









How do I use Chat Operation Code
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ChatClient.cs Copy
217         public bool Subscribe(string[] channels, int messagesFromHistory)
218         {
219             if (!this.CanChat)
220             {
221                 // TODO: log error
222                 return false;
223             }
224
225             if (channels == null || channels.Length == 0)
226             {
227                 this.LogWarning("Subscribe can't be called for empty or null cannels-list.");
228                 return false;
229             }
230
231             return this.SendChannelOperation(channels, (byte)ChatOperationCode.Subscribe, messagesFromHistory);
232         }
File name: ChatClient.cs Copy
245         public bool Unsubscribe(string[] channels)
246         {
247             if (!this.CanChat)
248             {
249                 // TODO: log error
250                 return false;
251             }
252
253             if (channels == null || channels.Length == 0)
254             {
255                 this.LogWarning("Unsubscribe can't be called for empty or null cannels-list.");
256                 return false;
257             }
258
259             return SendChannelOperation(channels, ChatOperationCode.Unsubscribe, 0);
260         }
File name: ChatClient.cs Copy
270         public bool PublishMessage(string channelName, object message)
271         {
272             if (!this.CanChat)
273             {
274                 // TODO: log error
275                 return false;
276             }
277
278             if (string.IsNullOrEmpty(channelName) || message == null)
279             {
280                 this.LogWarning("PublishMessage parameters must be non-null and not empty.");
281                 return false;
282             }
283
284             Dictionary parameters = new Dictionary
285                 {
286                     { (byte)ChatParameterCode.Channel, channelName },
287                     { (byte)ChatParameterCode.Message, message }
288                 };
289
290             return this.chatPeer.OpCustom((byte)ChatOperationCode.Publish, parameters, true);
291         }
File name: ChatClient.cs Copy
311         public bool SendPrivateMessage(string target, object message, bool encrypt)
312         {
313             if (!this.CanChat)
314             {
315                 // TODO: log error
316                 return false;
317             }
318
319             if (string.IsNullOrEmpty(target) || message == null)
320             {
321                 this.LogWarning("SendPrivateMessage parameters must be non-null and not empty.");
322                 return false;
323             }
324
325             Dictionary parameters = new Dictionary
326                 {
327                     { ChatParameterCode.UserId, target },
328                     { ChatParameterCode.Message, message }
329                 };
330
331             bool sent = this.chatPeer.OpCustom((byte)ChatOperationCode.SendPrivate, parameters, true, 0, encrypt);
332             return sent;
333         }
File name: ChatClient.cs Copy
343         /// The message object can be anything that Photon can serialize, including (but not limited to)
350         private bool SetOnlineStatus(int status, object message, bool skipMessage)
351         {
352             if (!this.CanChat)
353             {
354                 // TODO: log error
355                 return false;
356             }
357
358             Dictionary parameters = new Dictionary
359                 {
360                     { ChatParameterCode.Status, status },
361                 };
362
363             if (skipMessage)
364             {
365                 parameters[ChatParameterCode.SkipMessage] = true;
366             }
367             else
368             {
369                 parameters[ChatParameterCode.Message] = message;
370             }
371             return this.chatPeer.OpCustom(ChatOperationCode.UpdateStatus, parameters, true);
372         }
File name: ChatClient.cs Copy
433         public bool AddFriends(string[] friends)
434         {
435             if (!this.CanChat)
436             {
437                 // TODO: log error
438                 return false;
439             }
440
441             if (friends == null || friends.Length == 0)
442             {
443                 this.LogWarning("AddFriends can't be called for empty or null list.");
444                 return false;
445             }
446
447             Dictionary parameters = new Dictionary
448                 {
449                     { ChatParameterCode.Friends, friends },
450                 };
451             return this.chatPeer.OpCustom(ChatOperationCode.AddFriends, parameters, true);
452         }
File name: ChatClient.cs Copy
496         public bool RemoveFriends(string[] friends)
497         {
498             if (!this.CanChat)
499             {
500                 // TODO: log error
501                 return false;
502             }
503
504             if (friends == null || friends.Length == 0)
505             {
506                 this.LogWarning("RemoveFriends can't be called for empty or null list.");
507                 return false;
508             }
509
510             Dictionary parameters = new Dictionary
511                 {
512                     { ChatParameterCode.Friends, friends },
513                 };
514             return this.chatPeer.OpCustom(ChatOperationCode.RemoveFriends, parameters, true);
515         }
File name: ChatClient.cs Copy
598         void IPhotonPeerListener.OnOperationResponse(OperationResponse operationResponse)
599         {
600             switch (operationResponse.OperationCode)
601             {
602                 case (byte)ChatOperationCode.Authenticate:
603                     this.HandleAuthResponse(operationResponse);
604                     break;
605
606                 // the following operations usually don't return useful data and no error.
607                 case (byte)ChatOperationCode.Subscribe:
608                 case (byte)ChatOperationCode.Unsubscribe:
609                 case (byte)ChatOperationCode.Publish:
610                 case (byte)ChatOperationCode.SendPrivate:
611                 default:
612                     if (operationResponse.ReturnCode != 0)
613                     {
614                         ((IPhotonPeerListener)this).DebugReturn(DebugLevel.ERROR, string.Format("Chat Operation {0} failed (Code: {1}). Debug Message: {2}", operationResponse.OperationCode, operationResponse.ReturnCode, operationResponse.DebugMessage));
615                     }
616                     break;
617             }
618         }
File name: ChatClient.cs Copy
854         private bool AuthenticateOnFrontEnd()
855         {
856             if (CustomAuthenticationValues != null)
857             {
858                 var d = new Dictionary {{(byte)ChatParameterCode.Secret, CustomAuthenticationValues.Secret}};
859                 return this.chatPeer.OpCustom((byte)ChatOperationCode.Authenticate, d, true);
860             }
861             else
862             {
863                 Debug.WriteLine("Can't authenticate on front end server. CustomAuthValues is null");
864             }
865             return false;
866         }
File name: ChatPeer.cs Copy
31         public bool AuthenticateOnNameServer(string appId, string appVersion, string region, string userId, AuthenticationValues authValues)
32         {
33             if (this.DebugOut >= DebugLevel.INFO)
34             {
35                 this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
36             }
37
38             var opParameters = new Dictionary();
39
40             opParameters[ParameterCode.AppVersion] = appVersion;
41             opParameters[ParameterCode.ApplicationId] = appId;
42             opParameters[ParameterCode.Region] = region;
43
44             if (!string.IsNullOrEmpty(userId))
45             {
46                 opParameters[ParameterCode.UserId] = userId;
47             }
48
49             if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
50             {
51                 opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
52                 if (!string.IsNullOrEmpty(authValues.Secret))
53                 {
54                     opParameters[ParameterCode.Secret] = authValues.Secret;
55                 }
56                 else
57                 {
58                     if (!string.IsNullOrEmpty(authValues.AuthParameters))
59                     {
60                         opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthParameters;
61                     }
62                     if (authValues.AuthPostData != null)
63                     {
64                         opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
65                     }
66                 }
67             }
68
69             return this.OpCustom((byte)ChatOperationCode.Authenticate, opParameters, true, (byte)0, this.IsEncryptionAvailable);
70         }

Download file with original file name:ChatOperationCode

ChatOperationCode 117 lượt xem

Gõ tìm kiếm nhanh...