📄 session.cc
字号:
sprintf(buf,"Connecting to %s %-.*s%-.*s", mud.getFullName(), connectTimeout-time_left+1, filled_string, time_left-1, empty_string); status->setf (buf); } } if (nsw && last_nsw_update != current_time) { nsw->force_update(); last_nsw_update = current_time; }}void Session::set_prompt (const char *s, int len) { char buf[MAX_MUD_BUF]; memcpy(buf, s, len); buf[len] = NUL; embed_interp->run_quietly("sys/prompt", buf, buf); inputLine->set_prompt(buf);}void Session::establishConnection (bool quick_restore) { state = connected; stats.connect_time = current_time; // Send commands, if any if (!quick_restore && mud.commands.len()) interpreter.add(mud.commands, EXPAND_ALL); char buf[256]; sprintf(buf, "mcl - %s", mud.getFullName()); set_title(buf);}void Session::connectionEstablished() { // Called from Socket establishConnection(false); status->setf("Connection to %s successful", mud.getFullName());}void Session::errorEncountered(int) { status->setf ("%s - %s", mud.getFullName(), getErrorText()); close();}// Data from the MUD has arrivedvoid Session::inputReady() { char out_buf[MAX_MUD_BUF]; char temp_buf[MAX_MUD_BUF]; char *out; int code_pos; char *prompt_begin; int count; int i; count = read(temp_buf, MAX_MUD_BUF-1); globalStats.bytes_read += count; stats.bytes_read += count; // Filter through mudcompress mudcompress_receive(mcinfo, temp_buf, count); // Error? if (mudcompress_error(mcinfo)) { close(); status->setf ("%s - compression error", mud.getFullName()); return; } // Need to respond? const char *mc_response = mudcompress_response(mcinfo); if (mc_response) write(mc_response, strlen(mc_response)); while (mudcompress_pending(mcinfo) && pos < MAX_MUD_BUF-1) { // Get some data count = mudcompress_get(mcinfo, (char*) input_buffer + pos, MAX_MUD_BUF - pos - 1); if (count > 0 && chatServerSocket) chatServerSocket->handleSnooping((char*)(input_buffer+pos), count); prompt_begin = NULL; out = out_buf; /* If we have data from last call, this means we got some incomplete ansi */ if (pos) code_pos = 0; else code_pos = -1; /* Process the buffer */ for (i = 0; i < count + pos; i++) { /* Lose patience of code does not terminate within 16 characters */ if (code_pos >= 0 && i - code_pos > 16) code_pos = -1; /* IAC: next character is a telnet command */ if (input_buffer[i] == IAC) { if (++i < count + pos) /* just forget it if it appears at the end of a buffer */ { /* spec: handle prompts that split across reads */ if (input_buffer[i] == GA || input_buffer[i] == EOR) /* this is a prompt */ { /* if we have a prompt_begin, that's the start of * the prompt. If we don't, then the contents * of the 'prompt' buffer, plus any output we * have, is the prompt. */ if(!config->getOption(opt_snarf_prompt)) { if(prompt_begin) { int len = out - prompt_begin; char *buf = new char[len + 1]; memcpy(buf, prompt_begin+1, len); buf[len] = '\0'; embed_interp->run_quietly("sys/prompt", buf, buf); } } else if (prompt_begin) { set_prompt (prompt_begin + 1, out - prompt_begin - 1); if (!config->getOption(opt_showprompt)) out = prompt_begin + 1; } else { if (prompt[0] || out[0]) { unsigned char *temp = prompt + strlen ((char*)prompt); *out = NUL; strcat ((char*)prompt, out_buf); set_prompt ((char*)prompt, (int)strlen ((char*)prompt)); *temp = NUL; } if (!config->getOption(opt_showprompt)) out = out_buf; } // Insert a clear color code here // It'd be better to interpret color codes in the prompt properly, // but that is surprisingly hard to do *out++ = SET_COLOR; *out++ = bg_black|fg_white; // Is that really the *default* color? prompt[0] = NUL; prompt_begin = out; } // React to IAC WILL EOR and send back IAC DO EOR else if (input_buffer[i] == WILL && (i+1) < count+pos && input_buffer[i+1] == TELOPT_EOR) { i++; // @@ use telnet.h defines here write ("\377\375\31", 3); } /* Skip the next character if this is an option */ else if (input_buffer[i] >= WILL && input_buffer[i] <= DONT) i++; } continue; } // Escape sequence else if (input_buffer[i] == '\e') code_pos = i; // Attention else if (input_buffer[i] == '\a' && config->getOption(opt_mudbeep)) ::write(STDOUT_FILENO, "\a", 1); // use screen->flash() here? else if (code_pos == -1) { // not inside a color code, real text if (input_buffer[i] == '\n') { // Do regexp trigger magic bool cancel_line = triggerCheck(prompt_begin ? prompt_begin+1 : (char*) out_buf, prompt_begin ? out-prompt_begin-1: out-out_buf, &out); prompt_begin = out; if (cancel_line) { // We just gagged that line, so the \n which otherwise would be the beginning of the prompt // is eaten up. if (out > out_buf) prompt_begin = out-1; else prompt_begin = NULL; continue; } } if (input_buffer[i] != '\r') /* discard those */ *out++ = input_buffer[i]; /* Add to output buffer */ } /* Check if the code should terminate here */ if (code_pos >= 0 && isalpha (input_buffer[i])) { int color; /* Conver this color code to internal representation */ if ((color = colorConverter.convert (input_buffer + code_pos, i - code_pos + 1)) > 0) { *out++ = SET_COLOR; *out++ = color; } if (colorConverter.checkReportStatus()) { /* suggested by Chris Litchfield */ output->printf("\n(Sending location code\n"); writeMUD("\e[40;13R\n"); } code_pos = -1; } } *out = NUL; // Run triggers on incompletely received lines bool cancel_line = triggerCheck(prompt_begin ? prompt_begin+1 : (char*) out_buf, prompt_begin ? out-prompt_begin-1: out-out_buf, &out); prompt_begin = out; if (cancel_line) { // We just gagged that line, so the \n which otherwise would be the beginning of the prompt // is eaten up. if (out > out_buf) prompt_begin = out-1; else prompt_begin = NULL; } print (out_buf); /* Do we have some leftover data, an incomplete ANSI sequence? */ if (code_pos >= 0) { /* Copy so that the buffer is at the beginning of that code */ memcpy (input_buffer, input_buffer + code_pos, count + pos - code_pos); /* Next incoming data will be put there */ pos = count + pos - code_pos; } else pos = 0; /* spec: fix up partial lines for subsequent prompts */ if (prompt_begin) strcpy ((char*)prompt, prompt_begin); else if (strlen((char*)prompt) < MAX_MUD_BUF/4 && strlen(out_buf) < MAX_MUD_BUF/4) { // guard against too long lines strcat((char*)prompt, out_buf); } } // end while}void Session::show_timer() { timer = new TimerWindow(*this);}void Session::show_nsw() { nsw = new NetworkStateWindow(*this); statWindow = new StatWindow(*this);}bool Session::expand_macros(int key) { if (macros_disabled) return false; // This is a bit primitive currently Macro *m = mud.findMacro(key); if (m) { if (config->getOption(opt_echoinput)) { char buf[256]; snprintf (buf, sizeof(buf), "%c>> %s -> %s\n", SOFT_CR, key_name(m->key), ~m->text); print(buf); } interpreter.add(m->text, EXPAND_ALL); return true; } return false;}// Check triggers// Also do replacement: if replacing, adjust *outbool Session::triggerCheck (char *line, int len, char **new_out) { char *s; int old_len = len; // Len can be -1 if all we get is a \nprompt or such if ( len < 0) return false; char buf[MAX_MUD_BUF]; char uncolored[MAX_MUD_BUF]; char *out2 = uncolored; memcpy(buf, line, len); buf[len] = NUL; for (s = line; s < line+len; s++) { if ((unsigned char) *s == SET_COLOR) { s++; } else *out2++ = *s; } *out2 = NUL; if (!actions_disabled) mud.checkActionMatch(uncolored); mud.checkReplacement(buf, len, new_out); // Input stuff if (embed_interp->run_quietly("sys/output", buf, *new_out-len)) { int new_len = strlen(*new_out-len); *new_out += strlen(*new_out-len) - len; len = new_len; } // if we had a >0 char line and now have 0 line.. signal back that // the line shouldn't be shown at all if (old_len > 0 && len == 0) return true; else return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -