MCPcopy Create free account
hub / github.com/assaultcube/AC / nickcomplete

Function nickcomplete

source/src/command.cpp:708–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706}
707
708bool nickcomplete(char *s, bool reversedirection)
709{
710 static int nickcompleteidx;
711
712 char *cp = strrchr(s, ' '); // find last space
713 cp = cp ? cp + 1 : s;
714
715 if(nickcompletesize < 0)
716 {
717 nickcompletesize = (int)strlen(cp);
718 nickcompleteidx = reversedirection ? 0 : -1;
719 }
720
721 vector<int> matchingnames;
722 vector<const char *> matchingigs;
723 loopv(players) if(players[i] && !strncasecmp(players[i]->name, cp, nickcompletesize)) matchingnames.add(i); // find all matching player names first
724 if(nickcompletesize > 0 && *cp == ':') enumigraphs(matchingigs, cp + 1, nickcompletesize - 1); // find all matching igraphs
725 int totalmatches = matchingnames.length() + matchingigs.length();
726 if(totalmatches)
727 {
728 nickcompleteidx += reversedirection ? totalmatches - 1 : 1;
729 nickcompleteidx %= totalmatches;
730 bool isig = nickcompleteidx >= matchingnames.length();
731 const char *fillin = isig ? matchingigs[nickcompleteidx - matchingnames.length()] : players[matchingnames[nickcompleteidx]]->name;
732 if(*fillin == '/' && cp == s) *cp++ = ' ';
733 if(isig) cp++;
734 *cp = '\0';
735 concatstring(s, fillin);
736 return true;
737 }
738 return false;
739}
740
741enum { COMPLETE_FILE = 0, COMPLETE_LIST, COMPLETE_NICK };
742

Callers 2

commandcompleteFunction · 0.85
completeFunction · 0.85

Calls 5

enumigraphsFunction · 0.85
concatstringFunction · 0.85
loopvFunction · 0.70
addMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected