PrivateMessage
How do I use Private Message
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
342 public void OnPrivateMessage(string sender, object message, string channelName)
343 {
344 // as the ChatClient is buffering the messages for you, this GUI doesn't need to do anything here
345 // you also get messages that you sent yourself. in that case, the channelName is determinded by the target of your msg
346 }
File name: ChatClient.cs
Copy
299 public bool SendPrivateMessage(string target, object message)
300 {
301 return SendPrivateMessage(target, message, false);
302 }
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
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
576 void IPhotonPeerListener.OnEvent(EventData eventData)
577 {
578 switch (eventData.Code)
579 {
580 case ChatEventCode.ChatMessages:
581 this.HandleChatMessagesEvent(eventData);
582 break;
583 case ChatEventCode.PrivateMessage:
584 this.HandlePrivateMessageEvent(eventData);
585 break;
586 case ChatEventCode.StatusUpdate:
587 this.HandleStatusUpdate(eventData);
588 break;
589 case ChatEventCode.Subscribe:
590 this.HandleSubscribeEvent(eventData);
591 break;
592 case ChatEventCode.Unsubscribe:
593 this.HandleUnsubscribeEvent(eventData);
594 break;
595 }
596 }
File name: ChatClient.cs
Copy
688 private void HandlePrivateMessageEvent(EventData eventData)
689 {
690 //Console.WriteLine(SupportClass.DictionaryToString(eventData.Parameters));
691
692 var message = (object)eventData.Parameters[(byte)ChatParameterCode.Message];
693 var sender = (string)eventData.Parameters[(byte)ChatParameterCode.Sender];
694
695 string channelName;
696 if (this.UserId != null && this.UserId.Equals(sender))
697 {
698 var target = (string)eventData.Parameters[(byte)ChatParameterCode.UserId];
699 channelName = this.GetPrivateChannelNameByUser(target);
700 }
701 else
702 {
703 channelName = this.GetPrivateChannelNameByUser(sender);
704 }
705
706 ChatChannel channel;
707 if (!this.PrivateChannels.TryGetValue(channelName, out channel))
708 {
709 channel = new ChatChannel(channelName);
710 channel.IsPrivate = true;
711 this.PrivateChannels.Add(channel.Name, channel);
712 }
713
714 channel.Add(sender, message);
715 this.listener.OnPrivateMessage(sender, message, channelName);
716 }
PrivateMessage 123 lượt xem
Gõ tìm kiếm nhanh...