Publish









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

Featured Snippets


File name: ChatGui.cs Copy
215     private void GuiSendsMsg()
216     {
217         if (string.IsNullOrEmpty(this.inputLine))
218         {
219
220             GUI.FocusControl("");
221             return;
222         }
223
224         if (this.inputLine[0].Equals('\\'))
225         {
226             string[] tokens = this.inputLine.Split(new char[] {' '}, 2);
227             if (tokens[0].Equals("\\help"))
228             {
229                 this.PostHelpToCurrentChannel();
230             }
231             if (tokens[0].Equals("\\state"))
232             {
233                 int newState = int.Parse(tokens[1]);
234                 this.chatClient.SetOnlineStatus(newState, new string[] { "i am state " + newState }); // this is how you set your own state and (any) message
235             }
236             else if (tokens[0].Equals("\\subscribe") && !string.IsNullOrEmpty(tokens[1]))
237             {
238                 this.chatClient.Subscribe(tokens[1].Split(new char[] {' ', ','}));
239             }
240             else if (tokens[0].Equals("\\unsubscribe") && !string.IsNullOrEmpty(tokens[1]))
241             {
242                 this.chatClient.Unsubscribe(tokens[1].Split(new char[] {' ', ','}));
243             }
244             else if (tokens[0].Equals("\\clear"))
245             {
246                 if (this.doingPrivateChat)
247                 {
248                     this.chatClient.PrivateChannels.Remove(this.selectedChannelName);
249                 }
250                 else
251                 {
252                     ChatChannel channel;
253                     if (this.chatClient.TryGetChannel(this.selectedChannelName, this.doingPrivateChat, out channel))
254                     {
255                         channel.ClearMessages();
256                     }
257                 }
258             }
259             else if (tokens[0].Equals("\\msg") && !string.IsNullOrEmpty(tokens[1]))
260             {
261                 string[] subtokens = tokens[1].Split(new char[] {' ', ','}, 2);
262                 string targetUser = subtokens[0];
263                 string message = subtokens[1];
264                 this.chatClient.SendPrivateMessage(targetUser, message);
265             }
266         }
267         else
268         {
269             if (this.doingPrivateChat)
270             {
271                 this.chatClient.SendPrivateMessage(this.userIdInput, this.inputLine);
272             }
273             else
274             {
275                 this.chatClient.PublishMessage(this.selectedChannelName, this.inputLine);
276             }
277         }
278
279         this.inputLine = "";
280         GUI.FocusControl("");
281     }
File name: ChatGui.cs Copy
317     public void OnSubscribed(string[] channels, bool[] results)
318     {
319
320         // this demo can automatically send a "hi" to subscribed channels. in a game you usually only send user's input!!
321         if (this.DemoPublishOnSubscribe)
322         {
323             foreach (string channel in channels)
324             {
325                 this.chatClient.PublishMessage(channel, "says 'hi' in OnSubscribed(). "); // you don't HAVE to send a msg on join but you could.
326             }
327         }
328     }
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
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         }

Download file with original file name:Publish

Publish 112 lượt xem

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