/* * mount tunnel if there isn't one visible. */ static void mounttunnel(int ctlfd) { int fd; char *p, *np, *q; if (access(netdir, AEXIST) >= 0) return; p = smprint("/srv/%s", srvpt? srvpt: "ssh"); np = strdup(netdir); if (p == nil || np == nil) sysfatal("out of memory"); q = strstr(np, "/ssh"); if (q != nil) *q = '\0'; fd = open(p, ORDWR); if (fd < 0) { syslog(0, "ssh", "can't open %s: %r", p); hangup(ctlfd); exits("open"); } if (mount(fd, -1, np, MBEFORE, "") < 0) { syslog(0, "ssh", "can't mount %s in %s: %r", p, np); hangup(ctlfd); exits("can't mount"); } free(p); free(np); }
/** * netplay_disconnect * @netplay : pointer to netplay object * * Disconnect netplay. * * Returns: true (1) if successful. At present, cannot fail. **/ bool netplay_disconnect(netplay_t *netplay) { if (!netplay || !netplay->has_connection) return true; hangup(netplay); return true; }
int mdm_dial(char *phone,char *port) { int rc; char s[MAX_STRING],conn[MAX_STRING]; if((rc=tty_openport(port))) { write_log("can't open port: %s",tty_errs[rc]); return MC_BAD; } reset(); xstrcpy(s,cfgs(CFG_DIALPREFIX),MAX_STRING); xstrcat(s,phone,MAX_STRING); xstrcat(s,cfgs(CFG_DIALSUFFIX),MAX_STRING); tty_local(1); sline("Dialing %s",s);vidle(); rc=modem_chat(s,cfgsl(CFG_MODEMCONNECT),cfgsl(CFG_MODEMNODIAL),cfgsl(CFG_MODEMERROR), cfgsl(CFG_MODEMBUSY),cfgs(CFG_MODEMRINGING),cfgi(CFG_MAXRINGS), cfgi(CFG_WAITCARRIER),conn,MAX_STRING); sline("Modem said: %s",conn); xfree(connstr);connstr=xstrdup(conn); if(rc!=MC_OK) { write_log("got %s",conn); if(rc==MC_FAIL)hangup(); tty_close(); if(rc==MC_RING) { sline("RING found.."); sleep(2); execsh("killall -USR1 mgetty vgetty >/dev/null 2>&1"); } else sline("Call failed (%s)",mcs[rc]); return rc; } write_log("*** %s",conn); tty_local(0); return rc; }
static void listenloop(char *listfile, int ctlfd, char *buf, int size) { int fd, n; while ((fd = open(listfile, ORDWR)) >= 0) { n = read(fd, buf, size - 1); fprint(errfd, "read from listen file returned %d\n", n); if (n <= 0) { syslog(0, "ssh", "read on listen failed: %r"); break; } buf[n >= 0? n: 0] = '\0'; fprint(errfd, "read %s\n", buf); switch (fork()) { case 0: /* child */ close(ctlfd); newchannel(fd, netdir, atoi(buf)); /* never returns */ case -1: syslog(0, "ssh", "fork failed: %r"); hangup(ctlfd); exits("fork"); } close(fd); } if (fd < 0) syslog(0, "ssh", "listen failed: %r"); }
void mdm_done() { tty_local(1); hangup(); stat_collect(); tty_close(); }
static void do_hang(int askit) { int c = 0; if (askit) c = ask(_("Hang-up line?"), c7); if (c == 0) hangup(); }
void MainWin::initLayout() { //statusBar_ = new QStatusBar(this); /* main layout */ QHBoxLayout *hbox_main = new QHBoxLayout; //QVBoxLayout *vbox_left = new QVBoxLayout; vbox_left = new QVBoxLayout; QVBoxLayout *vbox_right = new QVBoxLayout; hbox_main->addLayout(vbox_left); hbox_main->addLayout(vbox_right); /* Left pane */ QHBoxLayout *hbox_url = new QHBoxLayout; hbox_url->addWidget(new QLabel(tr("Url:"))); hbox_url->addWidget(url_=new QLineEdit(tr("sip:")), 1); vbox_left->addLayout(hbox_url); /* Right pane */ vbox_right->addWidget((localUri_ = new QLabel)); vbox_right->addWidget((vidEnabled_ = new QCheckBox(tr("Enable &video")))); vbox_right->addWidget((previewButton_=new QPushButton(tr("Start &Preview")))); vbox_right->addWidget((callButton_=new QPushButton(tr("Call")))); vbox_right->addWidget((hangupButton_=new QPushButton(tr("Hangup")))); vbox_right->addWidget((quitButton_=new QPushButton(tr("Quit")))); #if PJMEDIA_HAS_VIDEO vidEnabled_->setCheckState(Qt::Checked); #else vidEnabled_->setCheckState(Qt::Unchecked); vidEnabled_->setEnabled(false); #endif /* Outest layout */ QVBoxLayout *vbox_outest = new QVBoxLayout; vbox_outest->addLayout(hbox_main); vbox_outest->addWidget((statusBar_ = new QLabel)); setLayout(vbox_outest); connect(previewButton_, SIGNAL(clicked()), this, SLOT(preview())); connect(callButton_, SIGNAL(clicked()), this, SLOT(call())); connect(hangupButton_, SIGNAL(clicked()), this, SLOT(hangup())); connect(quitButton_, SIGNAL(clicked()), this, SLOT(quit())); //connect(this, SIGNAL(close()), this, SLOT(quit())); connect(vidEnabled_, SIGNAL(stateChanged(int)), this, SLOT(onVidEnabledChanged(int))); // UI updates must be done in the UI thread! connect(this, SIGNAL(signalNewCall(int, bool)), this, SLOT(onNewCall(int, bool))); connect(this, SIGNAL(signalCallReleased()), this, SLOT(onCallReleased())); connect(this, SIGNAL(signalInitVideoWindow()), this, SLOT(initVideoWindow())); connect(this, SIGNAL(signalShowStatus(const QString&)), this, SLOT(doShowStatus(const QString&))); }
static void auth(char *buf, int n, int ctlfd) { int fd; fd = open("#¤/capuse", OWRITE); if (fd < 0) { syslog(0, "ssh", "server can't open capuse: %r"); hangup(ctlfd); exits("capuse"); } if (write(fd, buf, n) != n) { syslog(0, "ssh", "server write `%.*s' to capuse failed: %r", n, buf); hangup(ctlfd); exits("capuse"); } close(fd); }
do_ext(int c) { int x,y; switch(c) { case 31: setscroll(); break; case 59: /* edit user */ pullmenu(); break; case 60: /* view user stats */ break; case 61: /* sysop drop to dos */ todos(); break; /* case 62: /* commands */ curr_cursor(&x,&y); cursor(0,25); chooselist(); cursor(x,y); break;*/ case 63: /* disconnect w/o line noise */ hangup(); break; case 64: /* disconnect w/ line noise */ line_noise(); hangup(); break; case 65: /* finger/nuke user */ break; case 66: /* temp. sysop access */ break; case 67: /* spurt o' line noise */ line_noise(); break; case 68: /* chat w/ user */ chat(); put_char(12); break; } }
/* * We've got the hangup or term signal. */ static void hangsig(int sig) { if (stdwin) werror(_("Killed by signal %d !\n"), sig); if (capfp) fclose(capfp); keyboard(KUNINSTALL, 0); hangup(); modemreset(); leave("\n"); }
int command(isdn_ctrl *cmd) { int card; card = get_card_from_id(cmd->driver); if(!IS_VALID_CARD(card)) { pr_debug("Invalid param: %d is not a valid card id\n", card); return -ENODEV; } pr_debug("%s: Received %s command from Link Layer\n", sc_adapter[card]->devicename, commands[cmd->command]); /* * Dispatch the command */ switch(cmd->command) { case ISDN_CMD_IOCTL: { unsigned long cmdptr; scs_ioctl ioc; memcpy(&cmdptr, cmd->parm.num, sizeof(unsigned long)); if (copy_from_user(&ioc, (scs_ioctl __user *)cmdptr, sizeof(scs_ioctl))) { pr_debug("%s: Failed to verify user space 0x%x\n", sc_adapter[card]->devicename, cmdptr); return -EFAULT; } return sc_ioctl(card, &ioc); } case ISDN_CMD_DIAL: return dial(card, cmd->arg, cmd->parm.setup); case ISDN_CMD_HANGUP: return hangup(card, cmd->arg); case ISDN_CMD_ACCEPTD: return answer(card, cmd->arg); case ISDN_CMD_ACCEPTB: return acceptb(card, cmd->arg); case ISDN_CMD_CLREAZ: return clreaz(card, cmd->arg); case ISDN_CMD_SETEAZ: return seteaz(card, cmd->arg, cmd->parm.num); case ISDN_CMD_SETL2: return setl2(card, cmd->arg); case ISDN_CMD_SETL3: return setl3(card, cmd->arg); default: return -EINVAL; } return 0; }
value_t c_win32_hangup ( value_t loword, value_t hiword ) { HRASCONN hRasConn = (HRASCONN) MAKELPARAM ( Int_val ( loword ), Int_val ( hiword ) ); if ( debug_print ) printf ( "c_win32_hangup ( 0x%08x )\n", (unsigned)hRasConn ); hangup ( hRasConn ); return Val_true; }
VOID uart_wrport(WORD port, BYTE data) { int reg = port - uart_io_base; int retval; lprintf(LOG_DEBUG,"write of port: %x (%s) <- %02X", port, uart_reg_desc[reg], data); switch(reg) { case UART_BASE: if(uart_lcr_reg&UART_LCR_DLAB) { uart_divisor_latch_lsb = data; lprintf(LOG_DEBUG,"set divisor latch low byte: %02X", data); } else { lprintf(LOG_DEBUG,"WRITE DATA: %s", chr(data)); if(!WriteFile(wrslot,&data,sizeof(BYTE),&retval,NULL)) { lprintf(LOG_ERR,"!VDD_WRITE: WriteFile Error %d (size=%d)" ,GetLastError(),retval); } else { assert_interrupt(UART_IER_TX_EMPTY); reset_yield(); } } break; case UART_IER: if(uart_lcr_reg&UART_LCR_DLAB) { uart_divisor_latch_msb = data; lprintf(LOG_DEBUG,"set divisor latch high byte: %02X", data); } else uart_ier_reg = data; assert_interrupt(UART_IER_TX_EMPTY); /* should this be re-asserted for all writes? */ break; case UART_IIR: /* FCR not supported */ break; case UART_LCR: uart_lcr_reg = data; break; case UART_MCR: uart_mcr_reg = data; if((uart_mcr_reg&UART_MCR_DTR) == 0) /* Dropping DTR (i.e. "hangup") */ hangup(); break; case UART_SCRATCH: uart_scratch_reg = data; break; default: lprintf(LOG_ERR,"UNSUPPORTED register: %u", reg); break; } }
static void shutdownSMTP( unsigned int timeout /* IN timeout for reply in secs */ ) { if (CD() && timeout) SendSMTPCmdCheckReply("QUIT", 221, timeout); if (CD()) hangup(); closeline(); } /* shutdownSMTP */
/* * called by any proc when exiting to tear everything down. */ static void shutdown(void) { int i, pid; hangup(vnc->ctlfd); close(vnc->ctlfd); vnc->ctlfd = -1; close(vnc->datafd); vnc->datafd = -1; pid = getpid(); for(i = 0; i < NProcs; i++) if(pids[i] != pid) postnote(PNPROC, pids[i], killkin); }
/* * Answer an incoming call */ static int answer(int card, unsigned long channel) { if(!IS_VALID_CARD(card)) { pr_debug("Invalid param: %d is not a valid card id\n", card); return -ENODEV; } if(setup_buffers(card, channel+1)) { hangup(card, channel+1); return -ENOBUFS; } indicate_status(card, ISDN_STAT_BCONN,channel,NULL); pr_debug("%s: Answered incoming call on channel %lu\n", sc_adapter[card]->devicename, channel+1); return 0; }
static int acceptb(int card, unsigned long channel) { if(!IS_VALID_CARD(card)) { pr_debug("Invalid param: %d is not a valid card id\n", card); return -ENODEV; } if(setup_buffers(card, channel+1)) { hangup(card, channel+1); return -ENOBUFS; } pr_debug("%s: B-Channel connection accepted on channel %lu\n", sc_adapter[card]->devicename, channel+1); indicate_status(card, ISDN_STAT_BCONN, channel, NULL); return 0; }
void hup_hdlr (int sig) { #ifdef SIGHUP if (sig == SIGHUP) { signal (SIGHUP, hup_hdlr); Hup_caught = 1; /* do things different cause of 4.2 (sigh) */ Hup_caught = 1; if (Reading) /* doing tty i/o, and that is where hup came from */ { hangup (); } } #endif /* SIGHUP */ }
static int getdatafd(int ctlfd) { int fd; char *name; name = smprint("%s/data", netdir); fd = -1; if (name) fd = open(name, OREAD); if (fd < 0) { syslog(0, "ssh", "can't open %s: %r", name); hangup(ctlfd); exits("open data"); } free(name); return fd; }
void Quick_Bye(int onsig) { char *temp; int i; temp = calloc(PATH_MAX, sizeof(char)); Syslog('+', "Quick_Bye"); socket_shutdown(mypid); snprintf(temp, PATH_MAX, "%s/tmp/ftnd%d", getenv("FTND_ROOT"), getpid()); unlink(temp); free(temp); colour(LIGHTGRAY, BLACK); sleep(3); if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) { cookedport(); } /* * Ignore SIGHUP during hangup */ signal(SIGHUP, SIG_IGN); hangup(); /* * Prevent that we call die() if something goes wrong next */ for (i = 0; i < NSIG; i++) if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, SIG_DFL); free(pTTY); if (StartTime) free(StartTime); exit(FTNERR_OK); }
void TestPhoneCallImpl::transfer( const QString& ) { // Just hang up the call, simulating the transfer. hangup( QPhoneCall::CallOnly ); }
void eSocket::notifier(int what) { if ((what & eSocketNotifier::Read) && (mystate == Connection)) { int bytesavail=256; if (issocket) if (ioctl(getDescriptor(), FIONREAD, &bytesavail)<0) eDebug("FIONREAD failed.\n"); { if (issocket) { if (!bytesavail) // does the REMOTE END has closed the connection? (no Hungup here!) { writebuffer.clear(); close(); return; } } else // when operating on terminals, check for break { serial_icounter_struct icount; memset(&icount, 0, sizeof(icount)); if (!ioctl(getDescriptor(), TIOCGICOUNT, &icount)) { if (last_break == -1) last_break = icount.brk; else if (last_break != icount.brk) { last_break = icount.brk; readbuffer.fromfile(getDescriptor(), bytesavail); readbuffer.clear(); writebuffer.clear(); rsn->setRequested(rsn->getRequested()&~eSocketNotifier::Write); write(getDescriptor(), "BREAK!", 6); hangup(); return; } } else eDebug("TIOCGICOUNT failed(%m)"); } int r; if ((r=readbuffer.fromfile(getDescriptor(), bytesavail)) != bytesavail) if (issocket) eDebug("fromfile failed!"); readyRead_(); } } else if (what & eSocketNotifier::Write) { if ((mystate == Connection) || (mystate == Closing)) { if (!writebuffer.empty()) { bytesWritten_(writebuffer.tofile(getDescriptor(), 65536)); if (writebuffer.empty()) { rsn->setRequested(rsn->getRequested()&~eSocketNotifier::Write); if (mystate == Closing) { close(); // warning, we might get destroyed after close. return; } } } else eDebug("got ready to write, but nothin in buffer. strange."); if (mystate == Closing) close(); } else if (mystate == Connecting) { mystate=Connection; rsn->setRequested(rsn->getRequested()&~eSocketNotifier::Write); int res; socklen_t size=sizeof(res); ::getsockopt(getDescriptor(), SOL_SOCKET, SO_ERROR, &res, &size); if (!res) connected_(); else { close(); error_(res); } } } else if (what & eSocketNotifier::Hungup) { if (mystate == Connection || (mystate == Closing && issocket) ) { writebuffer.clear(); close(); } else if (mystate == Connecting) { int res; socklen_t size=sizeof(res); ::getsockopt(getDescriptor(), SOL_SOCKET, SO_ERROR, &res, &size); close(); error_(res); } } }
char sbbs_t::getkey(long mode) { char ch,coldkey,c=0,spin=sbbs_random(5); time_t last_telnet_cmd=0; if(!online || !input_thread_running) { YIELD(); // just in case someone is looping on getkey() when they shouldn't return(0); } sys_status&=~SS_ABORT; if((sys_status&SS_USERON || action==NODE_DFLT) && !(mode&(K_GETSTR|K_NOSPIN))) mode|=(useron.misc&SPIN); lncntr=0; timeout=time(NULL); if(mode&K_SPIN) outchar(' '); do { if(sys_status&SS_ABORT) { if(mode&K_SPIN) /* back space once if on spinning cursor */ backspace(); return(0); } if(mode&K_SPIN) { if(useron.misc&NO_EXASCII) { switch(c++) { case 0: outchar(BS); outchar('|'); break; case 1: outchar(BS); outchar('/'); break; case 2: outchar(BS); outchar('-'); break; case 3: outchar(BS); outchar('\\'); c=0; break; } } else { switch(spin) { case 0: switch(c++) { case 0: outchar(BS); outchar('³'); break; case 1: outchar(BS); outchar('/'); break; case 2: outchar(BS); outchar('Ä'); break; case 3: outchar(BS); outchar('\\'); c=0; break; } break; case 1: switch(c++) { case 0: outchar(BS); outchar('°'); break; case 1: outchar(BS); outchar('±'); break; case 2: outchar(BS); outchar('²'); break; case 3: outchar(BS); outchar('Û'); break; case 4: outchar(BS); outchar('²'); break; case 5: outchar(BS); outchar('±'); c=0; break; } break; case 2: switch(c++) { case 0: outchar(BS); outchar('-'); break; case 1: outchar(BS); outchar('='); break; case 2: outchar(BS); outchar('ð'); break; case 3: outchar(BS); outchar('='); c=0; break; } break; case 3: switch(c++) { case 0: outchar(BS); outchar('Ú'); break; case 1: outchar(BS); outchar('À'); break; case 2: outchar(BS); outchar('Ù'); break; case 3: outchar(BS); outchar('¿'); c=0; break; } break; case 4: switch(c++) { case 0: outchar(BS); outchar('Ü'); break; case 1: outchar(BS); outchar('Þ'); break; case 2: outchar(BS); outchar('ß'); break; case 3: outchar(BS); outchar('Ý'); c=0; break; } break; } } } ch=inkey(mode,mode&K_SPIN ? 250:1000); if(sys_status&SS_ABORT) return(0); now=time(NULL); if(ch) { if(mode&K_NUMBER && isprint(ch) && !isdigit(ch)) continue; if(mode&K_ALPHA && isprint(ch) && !isalpha(ch)) continue; if(mode&K_NOEXASC && ch&0x80) continue; if(mode&K_SPIN) backspace(); if(mode&K_COLD && ch>' ' && useron.misc&COLDKEYS) { if(mode&K_UPPER) outchar(toupper(ch)); else outchar(ch); while((coldkey=inkey(mode,1000))==0 && online && !(sys_status&SS_ABORT)) ; backspace(); if(coldkey==BS || coldkey==DEL) continue; if(coldkey>' ') ungetkey(coldkey); } if(mode&K_UPPER) return(toupper(ch)); return(ch); } if(sys_status&SS_USERON && !(sys_status&SS_LCHAT)) gettimeleft(); else if(online && now-answertime>SEC_LOGON && !(sys_status&SS_LCHAT)) { console&=~(CON_R_ECHOX|CON_L_ECHOX); console|=(CON_R_ECHO|CON_L_ECHO); bputs(text[TakenTooLongToLogon]); hangup(); } if(sys_status&SS_USERON && online && (timeleft/60)<(5-timeleft_warn) && !SYSOP && !(sys_status&SS_LCHAT)) { timeleft_warn=5-(timeleft/60); SAVELINE; attr(LIGHTGRAY); bprintf(text[OnlyXminutesLeft] ,((ushort)timeleft/60)+1,(timeleft/60) ? "s" : nulstr); RESTORELINE; } if(!(startup->options&BBS_OPT_NO_TELNET_GA) && now!=last_telnet_cmd && now-timeout>=60 && !((now-timeout)%60)) { // Let's make sure the socket is up // Sending will trigger a socket d/c detection send_telnet_cmd(TELNET_GA,0); last_telnet_cmd=now; } if(online==ON_REMOTE && !(console&CON_NO_INACT) && now-timeout>=cfg.sec_warn) { /* warning */ if(sys_status&SS_USERON && cfg.sec_warn!=cfg.sec_hangup) { SAVELINE; bputs(text[AreYouThere]); } else bputs("\7\7"); while(!inkey(K_NONE,100) && online && now-timeout>=cfg.sec_warn) { now=time(NULL); if(now-timeout>=cfg.sec_hangup) { if(online==ON_REMOTE) { console|=CON_R_ECHO; console&=~CON_R_ECHOX; } bputs(text[CallBackWhenYoureThere]); logline(nulstr,"Inactive"); hangup(); return(0); } } if(sys_status&SS_USERON && cfg.sec_warn!=cfg.sec_hangup) { bputs("\r\1n\1>"); RESTORELINE; } timeout=now; } } while(online); return(0); }
void run (int worker_id, int sock_fd, struct sockaddr addr, socklen_t addr_len) { headers_parse (sock_fd); if (headers_is_error (headers_get_state ()) || !headers_has_request()) { goto hangup; } char *name = get_request (1); char *strip = name; char response_buffer[255]; while (*strip == '.' || *strip == '/') strip++; if (!*strip) { fprintf (stderr, "%s: No such file or directory\n", name); goto _404; } int len = strlen (strip); int file_fd; char *file = malloc (2 + len + 1); file[0] = '.'; file[1] = '/'; memcpy (file + 2, strip, len); file[len + 2] = 0; file_fd = open (file, O_RDONLY); free (file); struct stat info; if (file_fd == -1 || fstat (file_fd, &info)) { if (file_fd > 0) { close (file_fd); } file_fd = 0; perror (name); goto _404; } response_init (200); char content_length[25]; sprintf (content_length, "%d", info.st_size); response_add ("Content-Length", content_length); if (write_headers (sock_fd)) { close (file_fd); goto _404; } len = read (file_fd, response_buffer, 255); while (len > 0) { if (write (sock_fd, response_buffer, len) < 0) { perror ("write"); break; } len = read (file_fd, response_buffer, 255); } if (file_fd > 0) { close (file_fd); } goto hangup; _404: response_init (404); write_headers (sock_fd); snprintf (response_buffer, 255, "File not found: '%s'\n", name); if (write (sock_fd, response_buffer, strlen (response_buffer)) < 0) { goto hangup; } goto hangup; hangup: headers_cleanup (); hangup (sock_fd); }
/* // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. */ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PNHMainWindow data; switch (message) { /*-----------------------------------------------------------------------*/ case WM_CREATE: { #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) SHMENUBARINFO menubar; #endif /* set window data */ data = (PNHMainWindow) malloc(sizeof(NHMainWindow)); if (!data) panic("out of memory"); ZeroMemory(data, sizeof(NHMainWindow)); data->mapAcsiiModeSave = MAP_MODE_ASCII12x16; SetWindowLong(hWnd, GWL_USERDATA, (LONG) data); GetNHApp()->hMainWnd = hWnd; /* create menu bar */ #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) ZeroMemory(&menubar, sizeof(menubar)); menubar.cbSize = sizeof(menubar); menubar.hwndParent = hWnd; menubar.dwFlags = 0; menubar.nToolBarId = IDC_WINHACK; menubar.hInstRes = GetNHApp()->hApp; #if defined(WIN_CE_POCKETPC) menubar.nBmpId = IDB_MENUBAR; menubar.cBmpImages = 2; #else menubar.nBmpId = 0; menubar.cBmpImages = 0; #endif if (!SHCreateMenuBar(&menubar)) panic("cannot create menu"); GetNHApp()->hMenuBar = menubar.hwndMB; #else GetNHApp()->hMenuBar = CommandBar_Create(GetNHApp()->hApp, hWnd, 1); if (!GetNHApp()->hMenuBar) panic("cannot create menu"); CommandBar_InsertMenubar(GetNHApp()->hMenuBar, GetNHApp()->hApp, IDC_WINHACK, 0); #endif CheckMenuItem( _get_main_menu(ID_VIEW), IDM_VIEW_KEYPAD, MF_BYCOMMAND | (GetNHApp()->bCmdPad ? MF_CHECKED : MF_UNCHECKED)); } break; /*-----------------------------------------------------------------------*/ case WM_MSNH_COMMAND: onMSNHCommand(hWnd, wParam, lParam); break; /*-----------------------------------------------------------------------*/ case WM_KEYDOWN: data = (PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA); /* translate arrow keys into nethack commands */ switch (wParam) { case VK_LEFT: if (STATEON(VK_CONTROL)) { /* scroll map window one line left */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_W)); } return 0; case VK_RIGHT: if (STATEON(VK_CONTROL)) { /* scroll map window one line right */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_E)); } return 0; case VK_UP: if (STATEON(VK_CONTROL)) { /* scroll map window one line up */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_N)); } return 0; case VK_DOWN: if (STATEON(VK_CONTROL)) { /* scroll map window one line down */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_S)); } return 0; case VK_HOME: if (STATEON(VK_CONTROL)) { /* scroll map window to upper left corner */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, MAKEWPARAM(SB_THUMBTRACK, 0), (LPARAM) NULL); SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, MAKEWPARAM(SB_THUMBTRACK, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_NW)); } return 0; case VK_END: if (STATEON(VK_CONTROL)) { /* scroll map window to lower right corner */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, MAKEWPARAM(SB_THUMBTRACK, ROWNO), (LPARAM) NULL); SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_HSCROLL, MAKEWPARAM(SB_THUMBTRACK, COLNO), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_SW)); } return 0; case VK_PRIOR: if (STATEON(VK_CONTROL)) { /* scroll map window one page up */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, MAKEWPARAM(SB_PAGEUP, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_NE)); } return 0; case VK_NEXT: if (STATEON(VK_CONTROL)) { /* scroll map window one page down */ SendMessage(mswin_hwnd_from_winid(WIN_MAP), WM_VSCROLL, MAKEWPARAM(SB_PAGEDOWN, 0), (LPARAM) NULL); } else { NHEVENT_KBD(KEYTABLE(KEY_SE)); } return 0; case VK_DECIMAL: case VK_DELETE: NHEVENT_KBD(KEYTABLE(KEY_WAITLOOK)); return 0; case VK_INSERT: NHEVENT_KBD(KEYTABLE(KEY_INV)); return 0; case VK_SUBTRACT: NHEVENT_KBD(KEYTABLE(KEY_MINUS)); return 0; case VK_ADD: NHEVENT_KBD(KEYTABLE(KEY_PLUS)); return 0; case VK_CLEAR: /* This is the '5' key */ NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING)); return 0; case VK_F4: if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) ? data->mapAcsiiModeSave : MAP_MODE_TILES); } else { mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode) ? MAP_MODE_ASCII_FIT_TO_SCREEN : MAP_MODE_TILES_FIT_TO_SCREEN); } return 0; case VK_F5: if (IS_MAP_ASCII(iflags.wc_map_mode)) { if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { mswin_select_map_mode(MAP_MODE_TILES_FIT_TO_SCREEN); } else { mswin_select_map_mode(MAP_MODE_TILES); } } else { if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { mswin_select_map_mode(MAP_MODE_ASCII_FIT_TO_SCREEN); } else { mswin_select_map_mode(data->mapAcsiiModeSave); } } return 0; case VK_RETURN: { int x, y; if (WIN_MAP != WIN_ERR) { mswin_map_get_cursor(mswin_hwnd_from_winid(WIN_MAP), &x, &y); } else { x = u.ux; y = u.uy; } NHEVENT_MS(CLICK_1, x, y); } return 0; } #if defined(WIN_CE_SMARTPHONE) if (GetNHApp()->bCmdPad && NHSPhoneTranslateKbdMessage(wParam, lParam, TRUE)) return 0; #endif return 1; /* end of WM_KEYDOWN */ /*-----------------------------------------------------------------------*/ #if defined(WIN_CE_SMARTPHONE) case WM_KEYUP: if (GetNHApp()->bCmdPad && NHSPhoneTranslateKbdMessage(wParam, lParam, FALSE)) return 0; return 1; /* end of WM_KEYUP */ #endif /*-----------------------------------------------------------------------*/ case WM_CHAR: #if defined(WIN_CE_SMARTPHONE) /* if smartphone cmdpad is up then translation happens - disable WM_CHAR processing to avoid double input */ if (GetNHApp()->bCmdPad) { return 1; } #endif if (wParam == '\n' || wParam == '\r' || wParam == C('M')) return 0; /* we already processed VK_RETURN */ /* all characters go to nethack except Ctrl-P that scrolls message * window up */ if (wParam == C('P') || wParam == C('p')) { SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), (LPARAM) NULL); } else { NHEVENT_KBD((lParam & 1 << 29) ? M(tolower(wParam)) : wParam); } return 0; /*-----------------------------------------------------------------------*/ case WM_COMMAND: /* process commands - menu commands mostly */ if (IsWindow(GetNHApp()->hPopupWnd)) { return SendMessage(GetNHApp()->hPopupWnd, message, wParam, lParam); } else if (onWMCommand(hWnd, wParam, lParam)) return DefWindowProc(hWnd, message, wParam, lParam); else return 0; /*-----------------------------------------------------------------------*/ case WM_ACTIVATE: if (LOWORD(wParam) != WA_INACTIVE) { #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) if (GetNHApp()->bFullScreen) SHFullScreen(GetNHApp()->hMainWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); else SHFullScreen(GetNHApp()->hMainWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); #endif mswin_layout_main_window(NULL); } break; case WM_SETTINGCHANGE: #if defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE) if (GetNHApp()->bFullScreen) SHFullScreen(GetNHApp()->hMainWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON); else SHFullScreen(GetNHApp()->hMainWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON); #endif mswin_layout_main_window(NULL); break; case WM_SIZE: mswin_layout_main_window(NULL); break; /*-----------------------------------------------------------------------*/ case WM_SETFOCUS: /* if there is a menu window out there - transfer input focus to it */ if (IsWindow(GetNHApp()->hPopupWnd)) { SetFocus(GetNHApp()->hPopupWnd); } break; /*-----------------------------------------------------------------------*/ case WM_CLOSE: { /* exit gracefully */ #ifdef SAFERHANGUP /* destroy popup window - it has its own loop and we need to return control to NetHack core at this point */ if (IsWindow(GetNHApp()->hPopupWnd)) SendMessage(GetNHApp()->hPopupWnd, WM_COMMAND, IDCANCEL, 0); /* tell NetHack core that "hangup" is requested */ hangup(1); #else dosave0(); terminate(EXIT_SUCCESS); #endif } return 0; /*-----------------------------------------------------------------------*/ case WM_DESTROY: { /* apparently we never get here TODO: work on exit routines - need to send WM_QUIT somehow */ /* clean up */ free((PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA)); SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); terminate(EXIT_SUCCESS); } break; /*-----------------------------------------------------------------------*/ default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/** * netplay_poll: * @netplay : pointer to netplay object * * Polls network to see if we have anything new. If our * network buffer is full, we simply have to block * for new input data. * * Returns: true (1) if successful, otherwise false (0). **/ static bool netplay_poll(void) { int res; if (!netplay_data->has_connection) return false; netplay_data->can_poll = false; get_self_input_state(netplay_data); /* No network side in spectate mode */ if (netplay_is_server(netplay_data) && netplay_data->spectate.enabled) return true; /* Read Netplay input, block if we're configured to stall for input every * frame */ if (netplay_data->stall_frames == 0 && netplay_data->read_frame_count <= netplay_data->self_frame_count) res = poll_input(netplay_data, true); else res = poll_input(netplay_data, false); if (res == -1) { hangup(netplay_data); return false; } /* Simulate the input if we don't have real input */ if (!netplay_data->buffer[netplay_data->self_ptr].have_remote) netplay_simulate_input(netplay_data, netplay_data->self_ptr); /* Consider stalling */ switch (netplay_data->stall) { case RARCH_NETPLAY_STALL_RUNNING_FAST: if (netplay_data->read_frame_count >= netplay_data->self_frame_count) netplay_data->stall = RARCH_NETPLAY_STALL_NONE; break; default: /* not stalling */ if (netplay_data->read_frame_count + netplay_data->stall_frames <= netplay_data->self_frame_count) { netplay_data->stall = RARCH_NETPLAY_STALL_RUNNING_FAST; netplay_data->stall_time = cpu_features_get_time_usec(); } } /* If we're stalling, consider disconnection */ if (netplay_data->stall) { retro_time_t now = cpu_features_get_time_usec(); /* Don't stall out while they're paused */ if (netplay_data->remote_paused) netplay_data->stall_time = now; else if (now - netplay_data->stall_time >= MAX_STALL_TIME_USEC) { /* Stalled out! */ hangup(netplay_data); return false; } } return true; }
static bool netplay_get_cmd(netplay_t *netplay) { uint32_t cmd; uint32_t flip_frame; uint32_t cmd_size; /* FIXME: This depends on delta_frame_ready */ netplay->timeout_cnt = 0; if (!socket_receive_all_blocking(netplay->fd, &cmd, sizeof(cmd))) return false; cmd = ntohl(cmd); if (!socket_receive_all_blocking(netplay->fd, &cmd_size, sizeof(cmd))) return false; cmd_size = ntohl(cmd_size); switch (cmd) { case NETPLAY_CMD_ACK: /* Why are we even bothering? */ return true; case NETPLAY_CMD_NAK: /* Disconnect now! */ return false; case NETPLAY_CMD_INPUT: { uint32_t buffer[WORDS_PER_FRAME]; unsigned i; if (cmd_size != WORDS_PER_FRAME * sizeof(uint32_t)) { RARCH_ERR("NETPLAY_CMD_INPUT received an unexpected payload size.\n"); return netplay_cmd_nak(netplay); } if (!socket_receive_all_blocking(netplay->fd, buffer, sizeof(buffer))) { RARCH_ERR("Failed to receive NETPLAY_CMD_INPUT input.\n"); return netplay_cmd_nak(netplay); } for (i = 0; i < WORDS_PER_FRAME; i++) buffer[i] = ntohl(buffer[i]); if (buffer[0] < netplay->read_frame_count) { /* We already had this, so ignore the new transmission */ return true; } else if (buffer[0] > netplay->read_frame_count) { /* Out of order = out of luck */ return netplay_cmd_nak(netplay); } /* The data's good! */ netplay->buffer[netplay->read_ptr].have_remote = true; memcpy(netplay->buffer[netplay->read_ptr].real_input_state, buffer + 1, sizeof(buffer) - sizeof(uint32_t)); netplay->read_ptr = NEXT_PTR(netplay->read_ptr); netplay->read_frame_count++; return true; } case NETPLAY_CMD_FLIP_PLAYERS: if (cmd_size != sizeof(uint32_t)) { RARCH_ERR("CMD_FLIP_PLAYERS received an unexpected command size.\n"); return netplay_cmd_nak(netplay); } if (!socket_receive_all_blocking( netplay->fd, &flip_frame, sizeof(flip_frame))) { RARCH_ERR("Failed to receive CMD_FLIP_PLAYERS argument.\n"); return netplay_cmd_nak(netplay); } flip_frame = ntohl(flip_frame); if (flip_frame < netplay->read_frame_count) { RARCH_ERR("Host asked us to flip users in the past. Not possible ...\n"); return netplay_cmd_nak(netplay); } netplay->flip ^= true; netplay->flip_frame = flip_frame; /* Force a rewind to assure the flip happens: This just prevents us * from skipping other past the flip because our prediction was * correct */ if (flip_frame < netplay->self_frame_count) netplay->force_rewind = true; RARCH_LOG("Netplay users are flipped.\n"); runloop_msg_queue_push("Netplay users are flipped.", 1, 180, false); return true; case NETPLAY_CMD_SPECTATE: RARCH_ERR("NETPLAY_CMD_SPECTATE unimplemented.\n"); return netplay_cmd_nak(netplay); case NETPLAY_CMD_DISCONNECT: hangup(netplay); return true; case NETPLAY_CMD_CRC: { uint32_t buffer[2]; size_t tmp_ptr = netplay->self_ptr; bool found = false; if (cmd_size != sizeof(buffer)) { RARCH_ERR("NETPLAY_CMD_CRC received unexpected payload size.\n"); return netplay_cmd_nak(netplay); } if (!socket_receive_all_blocking(netplay->fd, buffer, sizeof(buffer))) { RARCH_ERR("NETPLAY_CMD_CRC failed to receive payload.\n"); return netplay_cmd_nak(netplay); } buffer[0] = ntohl(buffer[0]); buffer[1] = ntohl(buffer[1]); /* Received a CRC for some frame. If we still have it, check if it * matched. This approach could be improved with some quick modular * arithmetic. */ do { if ( netplay->buffer[tmp_ptr].used && netplay->buffer[tmp_ptr].frame == buffer[0]) { found = true; break; } tmp_ptr = PREV_PTR(tmp_ptr); } while (tmp_ptr != netplay->self_ptr); if (!found) { /* Oh well, we got rid of it! */ return true; } if (buffer[0] <= netplay->other_frame_count) { /* We've already replayed up to this frame, so we can check it * directly */ uint32_t local_crc = netplay_delta_frame_crc( netplay, &netplay->buffer[tmp_ptr]); if (buffer[1] != local_crc) { /* Problem! */ netplay_cmd_request_savestate(netplay); } } else { /* We'll have to check it when we catch up */ netplay->buffer[tmp_ptr].crc = buffer[1]; } return true; } case NETPLAY_CMD_REQUEST_SAVESTATE: /* Delay until next frame so we don't send the savestate after the * input */ netplay->force_send_savestate = true; return true; case NETPLAY_CMD_LOAD_SAVESTATE: { uint32_t frame; /* Make sure we're ready for it */ if (netplay->quirks & NETPLAY_QUIRK_INITIALIZATION) { if (!netplay->is_replay) { netplay->is_replay = true; netplay->replay_ptr = netplay->self_ptr; netplay->replay_frame_count = netplay->self_frame_count; netplay_wait_and_init_serialization(netplay); netplay->is_replay = false; } else { netplay_wait_and_init_serialization(netplay); } } /* There is a subtlty in whether the load comes before or after the * current frame: * * If it comes before the current frame, then we need to force a * rewind to that point. * * If it comes after the current frame, we need to jump ahead, then * (strangely) force a rewind to the frame we're already on, so it * gets loaded. This is just to avoid having reloading implemented in * too many places. */ if (cmd_size > netplay->state_size + sizeof(uint32_t)) { RARCH_ERR("CMD_LOAD_SAVESTATE received an unexpected save state size.\n"); return netplay_cmd_nak(netplay); } if (!socket_receive_all_blocking(netplay->fd, &frame, sizeof(frame))) { RARCH_ERR("CMD_LOAD_SAVESTATE failed to receive savestate frame.\n"); return netplay_cmd_nak(netplay); } frame = ntohl(frame); if (frame != netplay->read_frame_count) { RARCH_ERR("CMD_LOAD_SAVESTATE loading a state out of order!\n"); return netplay_cmd_nak(netplay); } if (!socket_receive_all_blocking(netplay->fd, netplay->buffer[netplay->read_ptr].state, cmd_size - sizeof(uint32_t))) { RARCH_ERR("CMD_LOAD_SAVESTATE failed to receive savestate.\n"); return netplay_cmd_nak(netplay); } /* Skip ahead if it's past where we are */ if (frame > netplay->self_frame_count) { /* This is squirrely: We need to assure that when we advance the * frame in post_frame, THEN we're referring to the frame to * load into. If we refer directly to read_ptr, then we'll end * up never reading the input for read_frame_count itself, which * will make the other side unhappy. */ netplay->self_ptr = PREV_PTR(netplay->read_ptr); netplay->self_frame_count = frame - 1; } /* And force rewind to it */ netplay->force_rewind = true; netplay->savestate_request_outstanding = false; netplay->other_ptr = netplay->read_ptr; netplay->other_frame_count = frame; return true; } case NETPLAY_CMD_PAUSE: netplay->remote_paused = true; return true; case NETPLAY_CMD_RESUME: netplay->remote_paused = false; return true; default: break; } RARCH_ERR("Unknown netplay command received.\n"); return netplay_cmd_nak(netplay); }
/** * get_self_input_state: * @netplay : pointer to netplay object * * Grab our own input state and send this over the network. * * Returns: true (1) if successful, otherwise false (0). **/ static bool get_self_input_state(netplay_t *netplay) { uint32_t state[WORDS_PER_FRAME - 1] = {0, 0, 0}; struct delta_frame *ptr = &netplay->buffer[netplay->self_ptr]; if (!netplay_delta_frame_ready(netplay, ptr, netplay->self_frame_count)) return false; if (ptr->have_local) { /* We've already read this frame! */ return true; } if (!input_driver_is_libretro_input_blocked() && netplay->self_frame_count > 0) { unsigned i; settings_t *settings = config_get_ptr(); /* First frame we always give zero input since relying on * input from first frame screws up when we use -F 0. */ retro_input_state_t cb = netplay->cbs.state_cb; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { int16_t tmp = cb(settings->netplay.swap_input ? 0 : !netplay->port, RETRO_DEVICE_JOYPAD, 0, i); state[0] |= tmp ? 1 << i : 0; } for (i = 0; i < 2; i++) { int16_t tmp_x = cb(settings->netplay.swap_input ? 0 : !netplay->port, RETRO_DEVICE_ANALOG, i, 0); int16_t tmp_y = cb(settings->netplay.swap_input ? 0 : !netplay->port, RETRO_DEVICE_ANALOG, i, 1); state[1 + i] = (uint16_t)tmp_x | (((uint16_t)tmp_y) << 16); } } /* Here we construct the payload format: * frame { * uint32_t frame_number * uint32_t RETRO_DEVICE_JOYPAD state (top 16 bits zero) * uint32_t ANALOG state[0] * uint32_t ANALOG state[1] * } * * payload { * cmd (CMD_INPUT) * cmd_size (4 words) * frame * } */ netplay->packet_buffer[0] = htonl(NETPLAY_CMD_INPUT); netplay->packet_buffer[1] = htonl(WORDS_PER_FRAME * sizeof(uint32_t)); netplay->packet_buffer[2] = htonl(netplay->self_frame_count); netplay->packet_buffer[3] = htonl(state[0]); netplay->packet_buffer[4] = htonl(state[1]); netplay->packet_buffer[5] = htonl(state[2]); if (!netplay->spectate.enabled) /* Spectate sends in its own way */ { if (!socket_send_all_blocking(netplay->fd, netplay->packet_buffer, sizeof(netplay->packet_buffer), false)) { hangup(netplay); return false; } } memcpy(ptr->self_state, state, sizeof(state)); ptr->have_local = true; return true; }
/** * netplay_load_savestate * @netplay : pointer to netplay object * @serial_info : the savestate being loaded, NULL means "load it yourself" * @save : whether to save the provided serial_info into the frame buffer * * Inform Netplay of a savestate load and send it to the other side **/ void netplay_load_savestate(netplay_t *netplay, retro_ctx_serialize_info_t *serial_info, bool save) { uint32_t header[3]; retro_ctx_serialize_info_t tmp_serial_info; if (!netplay->has_connection) return; /* Record it in our own buffer */ if (save || !serial_info) { if (netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->self_ptr], netplay->self_frame_count)) { if (!serial_info) { tmp_serial_info.size = netplay->state_size; tmp_serial_info.data = netplay->buffer[netplay->self_ptr].state; if (!core_serialize(&tmp_serial_info)) return; tmp_serial_info.data_const = tmp_serial_info.data; serial_info = &tmp_serial_info; } else { if (serial_info->size <= netplay->state_size) { memcpy(netplay->buffer[netplay->self_ptr].state, serial_info->data_const, serial_info->size); } } } } /* We need to ignore any intervening data from the other side, and never rewind past this */ if (netplay->read_frame_count < netplay->self_frame_count) { netplay->read_ptr = netplay->self_ptr; netplay->read_frame_count = netplay->self_frame_count; } if (netplay->other_frame_count < netplay->self_frame_count) { netplay->other_ptr = netplay->self_ptr; netplay->other_frame_count = netplay->self_frame_count; } /* If we can't send it to the peer, loading a state was a bad idea */ if (netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION)) return; /* And send it to the peer (FIXME: this is an ugly way to do this) */ header[0] = htonl(NETPLAY_CMD_LOAD_SAVESTATE); header[1] = htonl(serial_info->size + sizeof(uint32_t)); header[2] = htonl(netplay->self_frame_count); if (!socket_send_all_blocking(netplay->fd, header, sizeof(header), false)) { hangup(netplay); return; } if (!socket_send_all_blocking(netplay->fd, serial_info->data_const, serial_info->size, false)) { hangup(netplay); return; } }
bool sbbs_t::answer() { char str[MAX_PATH+1],str2[MAX_PATH+1],c; char tmp[(MAX_PATH > CRYPT_MAX_TEXTSIZE ? MAX_PATH:CRYPT_MAX_TEXTSIZE)+1]; char tmpname[CRYPT_MAX_TEXTSIZE+1]; char path[MAX_PATH+1]; int i,l,in; struct tm tm; useron.number=0; answertime=logontime=starttime=now=time(NULL); /* Caller ID is IP address */ SAFECOPY(cid,client_ipaddr); memset(&tm,0,sizeof(tm)); localtime_r(&now,&tm); safe_snprintf(str,sizeof(str),"%s %s %s %02d %u Node %3u" ,hhmmtostr(&cfg,&tm,str2) ,wday[tm.tm_wday] ,mon[tm.tm_mon],tm.tm_mday,tm.tm_year+1900,cfg.node_num); logline("@ ",str); safe_snprintf(str,sizeof(str),"%s %s [%s]", connection, client_name, cid); logline("@+:",str); if(client_ident[0]) { safe_snprintf(str,sizeof(str),"Identity: %s",client_ident); logline("@*",str); } online=ON_REMOTE; if(sys_status&SS_RLOGIN) { if(incom(1000)==0) { for(i=0;i<(int)sizeof(str)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str[i]=in; } str[i]=0; for(i=0;i<(int)sizeof(str2)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str2[i]=in; } str2[i]=0; for(i=0;i<(int)sizeof(terminal)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; terminal[i]=in; } terminal[i]=0; lprintf(LOG_DEBUG,"Node %d RLogin: '******' / '%.*s' / '%s'" ,cfg.node_num ,LEN_ALIAS*2,str ,LEN_ALIAS*2,str2 ,terminal); SAFECOPY(rlogin_term, terminal); SAFECOPY(rlogin_name, str2); SAFECOPY(rlogin_pass, str); /* Truncate terminal speed (e.g. "/57600") from terminal-type string (but keep full terminal type/speed string in rlogin_term): */ truncstr(terminal,"/"); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; SAFEPRINTF(path,"%srlogin.cfg",cfg.ctrl_dir); if(!findstr(client.addr,path)) { SAFECOPY(tmp, rlogin_pass); for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } lprintf(LOG_WARNING,"Node %d !CLIENT IP NOT LISTED in %s" ,cfg.node_num,path); useron.number=0; hangup(); } } } else lprintf(LOG_INFO,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name); } if(rlogin_name[0]==0) { lprintf(LOG_NOTICE,"Node %d !RLogin: No user name received",cfg.node_num); sys_status&=~SS_RLOGIN; } } if(!(telnet_mode&TELNET_MODE_OFF)) { /* Disable Telnet Terminal Echo */ request_telnet_opt(TELNET_WILL,TELNET_ECHO); /* Will suppress Go Ahead */ request_telnet_opt(TELNET_WILL,TELNET_SUP_GA); /* Retrieve terminal type and speed from telnet client --RS */ request_telnet_opt(TELNET_DO,TELNET_TERM_TYPE); request_telnet_opt(TELNET_DO,TELNET_TERM_SPEED); request_telnet_opt(TELNET_DO,TELNET_SEND_LOCATION); request_telnet_opt(TELNET_DO,TELNET_NEGOTIATE_WINDOW_SIZE); request_telnet_opt(TELNET_DO,TELNET_NEW_ENVIRON); } #ifdef USE_CRYPTLIB if(sys_status&SS_SSH) { pthread_mutex_lock(&ssh_mutex); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_USERNAME, tmpname, &i); tmpname[i]=0; SAFECOPY(rlogin_name, tmpname); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_PASSWORD, tmp, &i); tmp[i]=0; SAFECOPY(rlogin_pass, tmp); pthread_mutex_unlock(&ssh_mutex); lprintf(LOG_DEBUG,"Node %d SSH login: '******'" ,cfg.node_num, tmpname); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, tmpname); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); /* crash here Sept-12-2010 str 0x06b3fc4c "(0000) Guest FAILED Password attempt: '*****@*****.**'" and Oct-6-2010 str 0x070ffc4c "(0000) Woot903 FAILED Password attempt: 'p67890pppsdsjhsdfhhfhnhnfhfhfdhjksdjkfdskw3902391=`'" char [261] */ logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } useron.number=0; hangup(); } } else lprintf(LOG_INFO,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name); } #endif /* Detect terminal type */ mswait(200); rioctl(IOFI); /* flush input buffer */ putcom( "\r\n" /* locate cursor at column 1 */ "\x1b[s" /* save cursor position (necessary for HyperTerm auto-ANSI) */ "\x1b[255B" /* locate cursor as far down as possible */ "\x1b[255C" /* locate cursor as far right as possible */ "\b_" /* need a printable at this location to actually move cursor */ "\x1b[6n" /* Get cursor position */ "\x1b[u" /* restore cursor position */ "\x1b[!_" /* RIP? */ "\x1b[30;40m\xc2\x9f""Zuul.connection.write('\\x1b""Are you the gatekeeper?')\xc2\x9c" /* ZuulTerm? */ "\x1b[0m_" /* "Normal" colors */ "\x1b[2J" /* clear screen */ "\x1b[H" /* home cursor */ "\xC" /* clear screen (in case not ANSI) */ "\r" /* Move cursor left (in case previous char printed) */ ); i=l=0; tos=1; lncntr=0; safe_snprintf(str, sizeof(str), "%s %s", VERSION_NOTICE, COPYRIGHT_NOTICE); strip_ctrl(str, str); center(str); while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */ c=incom(100)&0x7f; if(c==0) continue; i=0; if(l==0 && c!=ESC) // response must begin with escape char continue; str[l++]=c; if(c=='R') { /* break immediately if ANSI response */ mswait(500); break; } } while((c=(incom(100)&0x7f))!=0 && l<(int)sizeof(str)-1) str[l++]=c; str[l]=0; if(l) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_DEBUG,"Node %d received terminal auto-detection response: '%s'" ,cfg.node_num,tmp); if(str[0]==ESC && str[1]=='[' && str[l-1]=='R') { int x,y; if(terminal[0]==0) SAFECOPY(terminal,"ANSI"); autoterm|=(ANSI|COLOR); if(sscanf(str+2,"%u;%u",&y,&x)==2) { lprintf(LOG_DEBUG,"Node %d received ANSI cursor position report: %ux%u" ,cfg.node_num, x, y); /* Sanity check the coordinates in the response: */ if(x>=40 && x<=255) cols=x; if(y>=10 && y<=255) rows=y; } } truncsp(str); if(strstr(str,"RIPSCRIP")) { if(terminal[0]==0) SAFECOPY(terminal,"RIP"); logline("@R",strstr(str,"RIPSCRIP")); autoterm|=(RIP|COLOR|ANSI); } else if(strstr(str,"Are you the gatekeeper?")) { if(terminal[0]==0) SAFECOPY(terminal,"HTML"); logline("@H",strstr(str,"Are you the gatekeeper?")); autoterm|=HTML; } } else if(terminal[0]==0) SAFECOPY(terminal,"DUMB"); rioctl(IOFI); /* flush left-over or late response chars */ if(!autoterm && str[0]) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_NOTICE,"Node %d terminal auto-detection failed, response: '%s'" ,cfg.node_num, tmp); } /* AutoLogon via IP or Caller ID here */ if(!useron.number && !(sys_status&SS_RLOGIN) && (startup->options&BBS_OPT_AUTO_LOGON) && cid[0]) { useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid); if(useron.number) { getuserdat(&cfg, &useron); if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V'))) useron.number=0; } } if(!online) return(false); if(stricmp(terminal,"sexpots")==0) { /* dial-up connection (via SexPOTS) */ SAFEPRINTF2(str,"%s connection detected at %lu bps", terminal, cur_rate); logline("@S",str); node_connection = (ushort)cur_rate; SAFEPRINTF(connection,"%lu",cur_rate); SAFECOPY(cid,"Unknown"); SAFECOPY(client_name,"Unknown"); if(telnet_location[0]) { /* Caller-ID info provided */ SAFEPRINTF(str, "CID: %s", telnet_location); logline("@*",str); SAFECOPY(cid,telnet_location); truncstr(cid," "); /* Only include phone number in CID */ char* p=telnet_location; FIND_WHITESPACE(p); SKIP_WHITESPACE(p); if(*p) { SAFECOPY(client_name,p); /* CID name, if provided (maybe 'P' or 'O' if private or out-of-area) */ } } SAFECOPY(client.addr,cid); SAFECOPY(client.host,client_name); client_on(client_socket,&client,TRUE /* update */); } else { if(telnet_location[0]) { /* Telnet Location info provided */ SAFEPRINTF(str, "Telnet Location: %s", telnet_location); logline("@*",str); } } useron.misc&=~TERM_FLAGS; useron.misc|=autoterm; SAFECOPY(useron.comp,client_name); if(!useron.number && rlogin_name[0]!=0 && !(cfg.sys_misc&SM_CLOSED) && !matchuser(&cfg, rlogin_name, /* Sysop alias: */FALSE)) { lprintf(LOG_INFO,"Node %d UNKNOWN %s-specified USERNAME: %s, starting new user signup",cfg.node_num,client.protocol,rlogin_name); bprintf("%s: %s\r\n", text[UNKNOWN_USER], rlogin_name); newuser(); } if(!useron.number) { /* manual/regular logon */ /* Display ANSWER screen */ rioctl(IOSM|PAUSE); sys_status|=SS_PAUSEON; SAFEPRINTF(str,"%sanswer",cfg.text_dir); SAFEPRINTF(path,"%s.rip",str); if((autoterm&RIP) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.html",str); if((autoterm&HTML) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.ans",str); if((autoterm&ANSI) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.asc",str); if(fexistcase(path)) printfile(path, P_NOABORT); } } } sys_status&=~SS_PAUSEON; exec_bin(cfg.login_mod,&main_csi); } else /* auto logon here */ if(logon()==false) return(false); if(!useron.number) hangup(); /* Save the IP to the user's note */ if(cid[0]) { SAFECOPY(useron.note,cid); putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note); } /* Save host name to the user's computer description */ if(client_name[0]) { SAFECOPY(useron.comp,client_name); putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp); } if(!online) return(false); if(!(sys_status&SS_USERON)) { errormsg(WHERE,ERR_CHK,"User not logged on",0); hangup(); return(false); } if(useron.pass[0]) loginSuccess(startup->login_attempt_list, &client_addr); return(true); }