MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SendChatString

Function SendChatString

netcon/mtclient/chat_api.cpp:316–367  ·  view source on GitHub ↗

Send a string to be sent as chat, or scanned for messages (/msg string)

Source from the content-addressed store, hash-verified

314// Send a string to be sent as chat, or scanned for messages (/msg <user>
315// string)
316const char *SendChatString(const char *line, int raw) {
317 char szCmd[200];
318 char szTarget[50];
319 if (!Socket_connected)
320 return nullptr;
321
322 if (line[0] == '/') {
323
324 // Start off by getting the command
325 strcpy(szCmd, GetWordNum(0, line + 1));
326 if (stricmp(szCmd, "msg") == 0) {
327 strcpy(szTarget, GetWordNum(1, line + 1));
328 snprintf(szCmd, sizeof(szCmd), "PRIVMSG %s :%s\n\r", szTarget, line + strlen("/msg ") + strlen(szTarget) + 1);
329 send(Chatsock, szCmd, strlen(szCmd), 0);
330 szCmd[strlen(szCmd) - 2] = '\0';
331 return ParseIRCMessage(szCmd, MSG_LOCAL);
332 }
333 if (stricmp(szCmd, "me") == 0) {
334 snprintf(szCmd, sizeof(szCmd), "PRIVMSG %s :\001ACTION %s\001\n\r", szChat_channel, line + strlen("/me "));
335 send(Chatsock, szCmd, strlen(szCmd), 0);
336 szCmd[strlen(szCmd) - 2] = '\0';
337 return ParseIRCMessage(szCmd, MSG_LOCAL);
338 }
339 if (stricmp(szCmd, "xyz") == 0) {
340 // Special command to send raw irc commands
341 snprintf(szCmd, sizeof(szCmd), "%s\n\r", line + strlen("/xyz "));
342 send(Chatsock, szCmd, strlen(szCmd), 0);
343 return nullptr;
344 }
345 if (stricmp(szCmd, "list") == 0) {
346 snprintf(szCmd, sizeof(szCmd), "%s\n\r", line + 1);
347 send(Chatsock, szCmd, strlen(szCmd), 0);
348 return nullptr;
349 }
350 if (raw) {
351 snprintf(szCmd, sizeof(szCmd), "%s\n\r", line + 1);
352 send(Chatsock, szCmd, strlen(szCmd), 0);
353 return nullptr;
354 }
355 return "Unrecognized command";
356
357 } else {
358 if (szChat_channel[0]) {
359 snprintf(szCmd, sizeof(szCmd), "PRIVMSG %s :%s\n\r", szChat_channel, line);
360 send(Chatsock, szCmd, strlen(szCmd), 0);
361 szCmd[strlen(szCmd) - 2] = '\0';
362 return ParseIRCMessage(szCmd, MSG_LOCAL);
363 }
364 }
365
366 return nullptr;
367}
368
369// Returns a structure which contains a command and possible some data (like
370// a user joining or leaving) if one is waiting

Callers 8

MainMultiplayerMenuFunction · 0.85
SendWhisperFunction · 0.85
ConnectToChatServerFunction · 0.85
DisconnectFromChatServerFunction · 0.85
SetNewChatChannelFunction · 0.85
ParseIRCMessageFunction · 0.85
GetTrackerIdByUserFunction · 0.85
GetChannelByUserFunction · 0.85

Calls 2

GetWordNumFunction · 0.85
ParseIRCMessageFunction · 0.85

Tested by

no test coverage detected