Code: Show/Hide case MSG_Channel:
{ char *colon; char *pointybracket; char name[32]; char text[256]; char *command = &text[1]; colon = strstr(msg, ":"); pointybracket = strstr(msg, ">"); strncpy(name, colon + 1, pointybracket - colon - 1); strcpy(text, pointybracket + 2); for (int i = 0; i < strlen(text); i++) { text[i] = tolower(text[i]); } if (strchr(text, '.')) { if (strchr(text, '.') - text == 0) { Command c (command); Command *cp = &c; if (strcmp(c.cmd, "help") == 0) { gotHelp(p, cp); // I call it but nothing happens } else gotCommand(p, cp); // I call it but nothing happens } } } break; }; |
Code: Show/Hide EVENT_Chat,
/* Chat message has been received. [0] Type [1] Sound [2] Player class/UNUSED [3] Message */ |
Code: Show/Hide colon = strstr(msg, ":");
pointybracket = strstr(msg, ">"); /* becomes */ colon = strchr(msg, ':'); pointybracket = strstr(msg, "> "); |
50% Packetloss wrote: |
strstr looks for substrings, strchr looks for characters remember that strchr will return NULL if it doesnt find the desired character, although this should never happen, you should still write code to look out for it |