SendPrivateMessage
How do I use Send 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: 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 }
SendPrivateMessage 126 lượt xem
Gõ tìm kiếm nhanh...