void C4Network2IRCClient::OnMessage(bool fNotice, const char *szSender, const char *szTarget, const char *szText) { // Find channel, if not private. C4Network2IRCChannel *pChan = NULL; if(!SEqualNoCase(szTarget, Nick.getData())) pChan = getChannel(szTarget); // CTCP tagged data? const char X_DELIM = '\001'; if(szText[0] == X_DELIM) { // Process messages (it's very rarely more than one, but the spec allows it) const char *pMsg = szText + 1; while(*pMsg) { // Find end const char *pEnd = strchr(pMsg, X_DELIM); if(!pEnd) pEnd = pMsg + SLen(pMsg); // Copy CTCP query/reply, get tag StdStrBuf CTCP; CTCP.Copy(pMsg, pEnd - pMsg); StdStrBuf Tag; Tag.CopyUntil(CTCP.getData(), ' '); const char *szData = SSearch(CTCP.getData(), " "); StdStrBuf Sender; Sender.CopyUntil(szSender, '!'); // Process if(SEqualNoCase(Tag.getData(), "ACTION")) PushMessage(MSG_Action, szSender, szTarget, szData ? szData : ""); if(SEqualNoCase(Tag.getData(), "FINGER") && !fNotice) { StdStrBuf Answer; if(Config.Registered()) { Answer = Config.GetRegistrationData("Cuid"); } else { Answer = LoadResStr("IDS_PRC_UNREGUSER"); } Send("NOTICE", FormatString("%s :%cFINGER %s%c", Sender.getData(), X_DELIM, Answer.getData(), X_DELIM).getData()); } if(SEqualNoCase(Tag.getData(), "VERSION") && !fNotice) Send("NOTICE", FormatString("%s :%cVERSION " C4ENGINECAPTION ":" C4VERSION ":" C4_OS "%c", Sender.getData(), X_DELIM, X_DELIM).getData()); if(SEqualNoCase(Tag.getData(), "PING") && !fNotice) Send("NOTICE", FormatString("%s :%cPING %s%c", Sender.getData(), X_DELIM, szData, X_DELIM).getData()); // Get next message pMsg = pEnd; if(*pMsg == X_DELIM) pMsg++; } } // Standard message (not CTCP tagged): Push else PushMessage(fNotice ? MSG_Notice : MSG_Message, szSender, szTarget, szText); }
size_t C4Network2IRCClient::UnpackPacket(const StdBuf &rInBuf, const C4NetIO::addr_t &addr) { // Find line seperation const char *pSep = reinterpret_cast<const char *>(memchr(rInBuf.getData(), '\n', rInBuf.getSize())); if(!pSep) return 0; // Check if it's actually correct seperation (rarely the case) int iSize = pSep - getBufPtr<char>(rInBuf) + 1, iLength = iSize - 1; if(iLength && *(pSep - 1) == '\r') iLength--; // Copy the line StdStrBuf Buf; Buf.Copy(getBufPtr<char>(rInBuf), iLength); // Ignore prefix const char *pMsg = Buf.getData(); StdStrBuf Prefix; if(*pMsg == ':') { Prefix.CopyUntil(pMsg + 1, ' '); pMsg += Prefix.getLength() + 1; } // Strip whitespace while(*pMsg == ' ') pMsg++; // Ignore empty message if(!*pMsg) return iSize; // Get command StdStrBuf Cmd; Cmd.CopyUntil(pMsg, ' '); // Precess command const char *szParameters = SSearch(pMsg, " "); OnCommand(Prefix.getData(), Cmd.getData(), szParameters ? szParameters : ""); // Consume the line return iSize; }
// Helper for IRC command parameter parsing StdStrBuf ircExtractPar(const char **ppPar) { // No parameter left? if(!ppPar || !*ppPar || !**ppPar) return StdStrBuf(""); // Last parameter? StdStrBuf Result; if(**ppPar == ':') { // Reference everything after the double-colon Result.Ref(*ppPar + 1); *ppPar = NULL; } else { // Copy until next space (or end of string) Result.CopyUntil(*ppPar, ' '); // Go over parameters *ppPar += Result.getLength(); if(**ppPar == ' ') (*ppPar)++; else *ppPar = NULL; } // Done return Result; }
bool C4TexMapEntry::Init() { // Find material iMaterialIndex = ::MaterialMap.Get(Material.getData()); if (!MatValid(iMaterialIndex)) { DebugLogF("Error initializing material %s-%s: Invalid material!", Material.getData(), Texture.getData()); return false; } pMaterial = &::MaterialMap.Map[iMaterialIndex]; // Find texture StdStrBuf FirstTexture; FirstTexture.CopyUntil(Texture.getData(), '-'); C4Texture * sfcTexture = ::TextureMap.GetTexture(FirstTexture.getData()); if (!sfcTexture) { DebugLogF("Error initializing material %s-%s: Invalid texture!", Material.getData(), FirstTexture.getData()); Clear(); return false; } // Get overlay properties int32_t iOverlayType=pMaterial->OverlayType; int32_t iZoom=0; if (iOverlayType & C4MatOv_Exact) iZoom=1; if (iOverlayType & C4MatOv_HugeZoom) iZoom=4; // Create pattern MatPattern.Set(sfcTexture->Surface32, iZoom); return true; }
void C4EditCursor::UpdateStatusBar() { int32_t X=this->X, Y=this->Y; StdStrBuf str; switch (Mode) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4CNS_ModePlay: if (::MouseControl.GetCaption()) str.CopyUntil(::MouseControl.GetCaption(),'|'); break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4CNS_ModeEdit: str.Format("%i/%i (%s)",X,Y,Target ? (Target->GetName()) : LoadResStr("IDS_CNS_NOTHING") ); break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4CNS_ModeDraw: str.Format("%i/%i (%s)",X,Y,MatValid(GBackMat(X,Y)) ? ::MaterialMap.Map[GBackMat(X,Y)].Name : LoadResStr("IDS_CNS_NOTHING") ); break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } Console.DisplayInfoText(C4ConsoleGUI::CONSOLE_Cursor, str); }
void C4Network2IRCClient::OnNumericCommand(const char *szSender, int iCommand, const char *szParameters) { bool fShowMessage = true; // Get target StdStrBuf Target = ircExtractPar(&szParameters); // Handle command switch(iCommand) { case 433: // Nickname already in use { StdStrBuf DesiredNick = ircExtractPar(&szParameters); // Automatically try to choose a new one DesiredNick.AppendChar('_'); Send("NICK", DesiredNick.getData()); break; } case 376: // End of MOTD case 422: // MOTD missing // Let's take this a sign that the connection is established. OnConnected(); break; case 331: // No topic set case 332: // Topic notify / change { // Get Channel name and topic StdStrBuf Channel = ircExtractPar(&szParameters); StdStrBuf Topic = (iCommand == 332 ? ircExtractPar(&szParameters) : StdStrBuf("")); // Set it AddChannel(Channel.getData())->OnTopic(Topic.getData()); // Log if(Topic.getLength()) PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_TOPICIN"), Channel.getData(), Topic.getData()).getData()); } break; case 333: // Last topic change fShowMessage = false; // ignore break; case 353: // Names in channel { // Get Channel name and name list StdStrBuf Junk = ircExtractPar(&szParameters); // ??! StdStrBuf Channel = ircExtractPar(&szParameters); StdStrBuf Names = ircExtractPar(&szParameters); // Set it AddChannel(Channel.getData())->OnUsers(Names.getData(), Prefixes.getData()); fShowMessage = false; } break; case 366: // End of names list { // Get Channel name StdStrBuf Channel = ircExtractPar(&szParameters); // Finish AddChannel(Channel.getData())->OnUsersEnd(); fShowMessage = false; // Notify if(pNotify) pNotify->PushEvent(Ev_IRC_Message, this); } break; case 4: // Server version fShowMessage = false; // ignore break; case 5: // Server support string { while(szParameters && *szParameters) { // Get support-token. StdStrBuf Token = ircExtractPar(&szParameters); StdStrBuf Parameter; Parameter.CopyUntil(Token.getData(), '='); // Check if it's interesting and safe data if so. if(SEqualNoCase(Parameter.getData(), "PREFIX")) Prefixes.Copy(SSearch(Token.getData(), "=")); } fShowMessage = false; } break; } // Show embedded message, if any? if(fShowMessage) { // Check if first parameter is some sort of channel name C4Network2IRCChannel *pChannel = NULL; if(szParameters && *szParameters && *szParameters != ':') pChannel = getChannel(ircExtractPar(&szParameters).getData()); // Go over other parameters const char *pMsg = szParameters; while(pMsg && *pMsg && *pMsg != ':') pMsg = SSearch(pMsg, " "); // Show it if(pMsg && *pMsg) if(!pChannel) PushMessage(MSG_Server, szSender, Nick.getData(), pMsg + 1); else PushMessage(MSG_Status, szSender, pChannel->getName(), pMsg + 1); } }
void C4Network2IRCClient::OnCommand(const char *szSender, const char *szCommand, const char *szParameters) { CStdLock Lock(&CSec); // Numeric command? if(isdigit((unsigned char)*szCommand) && SLen(szCommand) == 3) { OnNumericCommand(szSender, atoi(szCommand), szParameters); return; } // Sender's nick StdStrBuf SenderNick; if(szSender) SenderNick.CopyUntil(szSender, '!'); // Ping? if(SEqualNoCase(szCommand, "PING")) Send("PONG", szParameters); // Message? if(SEqualNoCase(szCommand, "NOTICE") || SEqualNoCase(szCommand, "PRIVMSG")) { // Get target StdStrBuf Target = ircExtractPar(&szParameters); // Get text StdStrBuf Text = ircExtractPar(&szParameters); // Process message OnMessage(SEqualNoCase(szCommand, "NOTICE"), szSender, Target.getData(), Text.getData()); } // Channel join? if(SEqualNoCase(szCommand, "JOIN")) { // Get channel StdStrBuf Channel = ircExtractPar(&szParameters); C4Network2IRCChannel *pChan = AddChannel(Channel.getData()); // Add user pChan->OnJoin(SenderNick.getData()); // Myself? if(SenderNick == Nick) PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_YOUHAVEJOINEDCHANNEL"), Channel.getData()).getData()); else PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_HASJOINEDTHECHANNEL"), SenderNick.getData()).getData()); } // Channel part? if(SEqualNoCase(szCommand, "PART")) { // Get channel StdStrBuf Channel = ircExtractPar(&szParameters); C4Network2IRCChannel *pChan = AddChannel(Channel.getData()); // Get message StdStrBuf Comment = ircExtractPar(&szParameters); // Remove user pChan->OnPart(SenderNick.getData(), Comment.getData()); // Myself? if(SenderNick == Nick) { DeleteChannel(pChan); PushMessage(MSG_Status, szSender, Nick.getData(), FormatString(LoadResStr("IDS_MSG_YOUHAVELEFTCHANNEL"), Channel.getData(), Comment.getData()).getData()); } else PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_HASLEFTTHECHANNEL"), SenderNick.getData(), Comment.getData()).getData()); } // Kick? if(SEqualNoCase(szCommand, "KICK")) { // Get channel StdStrBuf Channel = ircExtractPar(&szParameters); C4Network2IRCChannel *pChan = AddChannel(Channel.getData()); // Get kicked user StdStrBuf Kicked = ircExtractPar(&szParameters); // Get message StdStrBuf Comment = ircExtractPar(&szParameters); // Remove user pChan->OnKick(Kicked.getData(), Comment.getData()); // Myself? if(Kicked == Nick) { DeleteChannel(pChan); PushMessage(MSG_Status, szSender, Nick.getData(), FormatString(LoadResStr("IDS_MSG_YOUWEREKICKEDFROMCHANNEL"), Channel.getData(), Comment.getData()).getData()); } else PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_WASKICKEDFROMTHECHANNEL"), Kicked.getData(), Comment.getData()).getData()); } // Quit? if(SEqualNoCase(szCommand, "QUIT")) { // Get comment StdStrBuf Comment = ircExtractPar(&szParameters); // Format status message StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_HASDISCONNECTED"), SenderNick.getData(), Comment.getData()); // Remove him from all channels for(C4Network2IRCChannel *pChan = pChannels; pChan; pChan = pChan->Next) if(pChan->getUser(SenderNick.getData())) { pChan->OnPart(SenderNick.getData(), "Quit"); PushMessage(MSG_Status, szSender, pChan->getName(), Message.getData()); } } // Topic change? if(SEqualNoCase(szCommand, "TOPIC")) { // Get channel and topic StdStrBuf Channel = ircExtractPar(&szParameters); StdStrBuf Topic = ircExtractPar(&szParameters); // Set topic AddChannel(Channel.getData())->OnTopic(Topic.getData()); // Message PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_CHANGESTHETOPICTO"), SenderNick.getData(), Topic.getData()).getData()); } // Mode? if(SEqualNoCase(szCommand, "MODE")) { // Get all data StdStrBuf Channel = ircExtractPar(&szParameters); StdStrBuf Flags = ircExtractPar(&szParameters); StdStrBuf What = ircExtractPar(&szParameters); // Make sure it's a channel C4Network2IRCChannel *pChan = getChannel(Channel.getData()); if(pChan) // Ask for names, because user prefixes might be out of sync Send("NAMES", Channel.getData()); // Show Message PushMessage(MSG_Status, szSender, Channel.getData(), FormatString(LoadResStr("IDS_MSG_SETSMODE"), SenderNick.getData(), Flags.getData(), What.getData()).getData()); } // Error? if(SEqualNoCase(szCommand, "ERROR")) { // Get message StdStrBuf Message = ircExtractPar(&szParameters); // Push it PushMessage(MSG_Server, szSender, Nick.getData(), Message.getData()); } // Nickchange? if(SEqualNoCase(szCommand, "NICK")) { // Get new nick StdStrBuf NewNick = ircExtractPar(&szParameters); // Format status message StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_ISNOWKNOWNAS"), SenderNick.getData(), NewNick.getData()); // Rename on all channels for(C4Network2IRCChannel *pChan = pChannels; pChan; pChan = pChan->Next) if(pChan->getUser(SenderNick.getData())) { pChan->OnPart(SenderNick.getData(), "Nickchange"); pChan->OnJoin(NewNick.getData()); PushMessage(MSG_Status, szSender, pChan->getName(), Message.getData()); } // Self? if(SenderNick == Nick) Nick = NewNick; } }
C4AulDebug::ProcessLineResult C4AulDebug::ProcessLine(const StdStrBuf &Line) { // Get command StdStrBuf Cmd; Cmd.CopyUntil(Line.getData(), ' '); // Get data const char *szData = Line.getPtr(Cmd.getLength()); if (*szData) szData++; // Identify command const char *szCmd = Cmd.getData(); if (SEqualNoCase(szCmd, "HELP")) return ProcessLineResult(false, "Yeah, like I'm going to explain that /here/"); else if (SEqualNoCase(szCmd, "BYE") || SEqualNoCase(szCmd, "QUIT")) C4NetIOTCP::Close(PeerAddr); else if (SEqualNoCase(szCmd, "SAY")) ::Control.DoInput(CID_Message, new C4ControlMessage(C4CMT_Normal, szData), CDT_Direct); else if (SEqualNoCase(szCmd, "CMD")) ::MessageInput.ProcessCommand(szData); else if (SEqualNoCase(szCmd, "STP") || SEqualNoCase(szCmd, "S")) eState = DS_Step; else if (SEqualNoCase(szCmd, "GO") || SEqualNoCase(szCmd, "G")) eState = DS_Go; else if (SEqualNoCase(szCmd, "STO") || SEqualNoCase(szCmd, "O")) eState = DS_StepOver; else if (SEqualNoCase(szCmd, "STR") || SEqualNoCase(szCmd, "R")) eState = DS_StepOut; else if (SEqualNoCase(szCmd, "EXC") || SEqualNoCase(szCmd, "E")) { C4AulScriptContext* context = pExec->GetContext(pExec->GetContextDepth()-1); int32_t objectNum = C4ControlScript::SCOPE_Global; if (context && context->Obj && context->Obj->GetObject()) objectNum = context->Obj->GetObject()->Number; ::Control.DoInput(CID_Script, new C4ControlScript(szData, objectNum, true), CDT_Decide); } else if (SEqualNoCase(szCmd, "PSE")) if (Game.IsPaused()) { Game.Unpause(); return ProcessLineResult(true, "Game unpaused."); } else { Game.Pause(); return ProcessLineResult(true, "Game paused."); } else if (SEqualNoCase(szCmd, "LST")) { for (C4AulScript* script = ScriptEngine.Child0; script; script = script->Next) { SendLine(RelativePath(script->ScriptName)); } } // toggle breakpoint else if (SEqualNoCase(szCmd, "TBR")) { using namespace std; // FIXME: this doesn't find functions which were included/appended string scriptPath = szData; size_t colonPos = scriptPath.find(':'); if (colonPos == string::npos) return ProcessLineResult(false, "Missing line in breakpoint request"); int line = atoi(&scriptPath[colonPos+1]); scriptPath.erase(colonPos); C4AulScript *script; for (script = ScriptEngine.Child0; script; script = script->Next) { if (SEqualNoCase(RelativePath(script->ScriptName), scriptPath.c_str())) break; } auto sh = script ? script->GetScriptHost() : NULL; if (sh) { C4AulBCC * found = NULL; for (auto script = ::ScriptEngine.Child0; script; script = script->Next) for (C4PropList *props = script->GetPropList(); props; props = props->GetPrototype()) for (auto fname = props->EnumerateOwnFuncs(); fname; fname = props->EnumerateOwnFuncs(fname)) { C4Value val; if (!props->GetPropertyByS(fname, &val)) continue; auto func = val.getFunction(); if (!func) continue; auto sfunc = func->SFunc(); if (!sfunc) continue; if (sfunc->pOrgScript != sh) continue; for (auto chunk = sfunc->GetCode(); chunk->bccType != AB_EOFN; chunk++) { if (chunk->bccType == AB_DEBUG) { int lineOfThisOne = sfunc->GetLineOfCode(chunk); if (lineOfThisOne == line) { found = chunk; goto Found; } } } } Found: if (found) found->Par.i = !found->Par.i; // activate breakpoint else return ProcessLineResult(false, "Can't set breakpoint (wrong line?)"); } else return ProcessLineResult(false, "Can't find script"); } else if (SEqualNoCase(szCmd, "SST")) { std::list<StdStrBuf*>::iterator it = StackTrace.begin(); for (it++; it != StackTrace.end(); it++) { SendLine("AT", (*it)->getData()); } SendLine("EST"); } else if (SEqualNoCase(szCmd, "VAR")) { C4Value *val = NULL; int varIndex; C4AulScriptContext* pCtx = pExec->GetContext(pExec->GetContextDepth() - 1); if (pCtx) { if ((varIndex = pCtx->Func->ParNamed.GetItemNr(szData)) != -1) { val = &pCtx->Pars[varIndex]; } else if ((varIndex = pCtx->Func->VarNamed.GetItemNr(szData)) != -1) { val = &pCtx->Vars[varIndex]; } } const char* typeName = val ? GetC4VName(val->GetType()) : "any"; StdStrBuf output = FormatString("%s %s %s", szData, typeName, val ? val->GetDataString().getData() : "Unknown"); SendLine("VAR", output.getData()); } else return ProcessLineResult(false, "Can't do that"); return ProcessLineResult(true, ""); }