|
|
1.1 ! root 1: /* chat.c */ ! 2: ! 3: /* Synchronet for *nix sysop chat routines */ ! 4: ! 5: /* $Id: chat.c,v 1.14 2006/05/08 18:58:21 deuce Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include <sys/types.h> ! 39: #include <utime.h> ! 40: ! 41: #include "ciolib.h" ! 42: #define __COLORS ! 43: #include "sbbs.h" ! 44: #include "chat.h" ! 45: ! 46: #define PCHAT_LEN 1000 /* Size of Private chat file */ ! 47: ! 48: typedef struct { ! 49: int left; ! 50: int top; ! 51: int right; ! 52: int bottom; ! 53: int x; ! 54: int y; ! 55: int colour; ! 56: } WINDOW; ! 57: ! 58: WINDOW uwin; ! 59: WINDOW swin; ! 60: ! 61: int togglechat(scfg_t *cfg, int node_num, node_t *node, int on) ! 62: { ! 63: static int org_act; ! 64: ! 65: int nodefile; ! 66: if(getnodedat(cfg,node_num,node,&nodefile)) { ! 67: return(FALSE); ! 68: } ! 69: if(on) { ! 70: org_act=node->action; ! 71: if(org_act==NODE_PCHT) ! 72: org_act=NODE_MAIN; ! 73: node->misc|=NODE_LCHAT; ! 74: } else { ! 75: node->action=org_act; ! 76: node->misc&=~NODE_LCHAT; ! 77: } ! 78: putnodedat(cfg,node_num,node,nodefile); ! 79: return(TRUE); ! 80: } ! 81: ! 82: void drawchatwin(box_t *boxch, char* topname, char* botname) { ! 83: struct text_info ti; ! 84: int i; ! 85: ! 86: _wscroll=0; ! 87: gettextinfo(&ti); ! 88: textcolor(WHITE); ! 89: textbackground(BLACK); ! 90: clrscr(); ! 91: uwin.top=1; ! 92: uwin.left=1; ! 93: uwin.right=ti.screenwidth; ! 94: uwin.bottom=ti.screenheight/2-1; ! 95: uwin.colour=GREEN; ! 96: swin.top=ti.screenheight/2+1; ! 97: swin.left=1; ! 98: swin.right=ti.screenwidth; ! 99: swin.bottom=ti.screenheight; ! 100: swin.colour=LIGHTGREEN; ! 101: ! 102: gotoxy(1,ti.screenheight/2); ! 103: putch(196); ! 104: putch(196); ! 105: putch(196); ! 106: putch(196); ! 107: putch(180); ! 108: cputs(topname); ! 109: putch(195); ! 110: for(i=wherex();i<=ti.screenwidth;i++) ! 111: putch(196); ! 112: ! 113: _wscroll=1; ! 114: } ! 115: ! 116: int chatchar(WINDOW *win, int ch) { ! 117: window(win->left,win->top,win->right,win->bottom); ! 118: gotoxy(win->x,win->y); ! 119: textcolor(win->colour); ! 120: putch(ch); ! 121: if(ch=='\r') ! 122: putch('\n'); ! 123: win->x=wherex(); ! 124: win->y=wherey(); ! 125: return(0); ! 126: } ! 127: ! 128: int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallback)(void)) { ! 129: int in,out; ! 130: char inpath[MAX_PATH]; ! 131: char outpath[MAX_PATH]; ! 132: char usrname[128]; ! 133: char *p; ! 134: char ch; ! 135: time_t now; ! 136: time_t last_nodechk=0; ! 137: struct text_info ti; ! 138: char *buf; ! 139: ! 140: gettextinfo(&ti); ! 141: if((buf=(char *)alloca(ti.screenwidth*ti.screenheight*2))==NULL) { ! 142: return(-1); ! 143: } ! 144: ! 145: if(getnodedat(cfg,nodenum,node,NULL)) ! 146: return(-1); ! 147: ! 148: username(cfg,node->useron,usrname); ! 149: ! 150: gettext(1,1,ti.screenwidth,ti.screenheight,buf); ! 151: drawchatwin(boxch,usrname,cfg->sys_op); ! 152: ! 153: sprintf(outpath,"%slchat.dab",cfg->node_path[nodenum-1]); ! 154: if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE ! 155: ,S_IREAD|S_IWRITE))==-1) ! 156: return(-1); ! 157: ! 158: sprintf(inpath,"%schat.dab",cfg->node_path[nodenum-1]); ! 159: if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE ! 160: ,S_IREAD|S_IWRITE))==-1) { ! 161: close(out); ! 162: return(-1); ! 163: } ! 164: ! 165: if((p=(char *)alloca(PCHAT_LEN))==NULL) { ! 166: close(in); ! 167: close(out); ! 168: return(-1); ! 169: } ! 170: memset(p,0,PCHAT_LEN); ! 171: write(in,p,PCHAT_LEN); ! 172: write(out,p,PCHAT_LEN); ! 173: lseek(in,0,SEEK_SET); ! 174: lseek(out,0,SEEK_SET); ! 175: ! 176: togglechat(cfg,nodenum,node,TRUE); ! 177: ! 178: while(in != -1) { ! 179: ! 180: now=time(NULL); ! 181: if(now!=last_nodechk) { ! 182: ! 183: if(timecallback != NULL) ! 184: timecallback(); ! 185: ! 186: if(getnodedat(cfg,nodenum,node,NULL)!=0) ! 187: break; ! 188: last_nodechk=now; ! 189: } ! 190: if(node->misc&NODE_LCHAT) { ! 191: if(kbhit()) { ! 192: ch=getch(); ! 193: if(ch==ESC || ch==3) { ! 194: close(in); ! 195: in=-1; ! 196: } ! 197: if(ch==0 || ch==-1) { /* Special keys... eat 'em. */ ! 198: getch(); ! 199: } ! 200: } ! 201: YIELD(); ! 202: continue; ! 203: } ! 204: ! 205: if(node->status==NODE_WFC || node->status>NODE_QUIET || node->action!=NODE_PCHT) { ! 206: close(in); ! 207: in=-1; ! 208: } ! 209: ! 210: utime(inpath,NULL); ! 211: _setcursortype(_NORMALCURSOR); ! 212: while(1) { ! 213: switch(read(in,&ch,1)) { ! 214: case -1: ! 215: close(in); ! 216: in=-1; ! 217: break; ! 218: ! 219: case 0: ! 220: lseek(in,0,SEEK_SET); /* Wrapped */ ! 221: continue; ! 222: ! 223: case 1: ! 224: lseek(in,-1L,SEEK_CUR); ! 225: if(ch) { ! 226: chatchar(&uwin,ch); ! 227: ch=0; ! 228: write(in,&ch,1); ! 229: continue; ! 230: } ! 231: break; ! 232: } ! 233: break; ! 234: } ! 235: ! 236: if(kbhit()) { ! 237: ch=getch(); ! 238: switch(ch) { ! 239: case 0: /* Special Chars */ ! 240: case -1: ! 241: ch=0; ! 242: getch(); ! 243: break; ! 244: ! 245: case ESC: ! 246: case 3: ! 247: close(in); ! 248: in=-1; ! 249: continue; ! 250: ! 251: default: ! 252: if(lseek(out,0,SEEK_CUR)>=PCHAT_LEN) ! 253: lseek(out,0,SEEK_SET); ! 254: chatchar(&swin,ch); ! 255: switch(write(out,&ch,1)) { ! 256: case -1: ! 257: close(in); ! 258: in=-1; ! 259: break; ! 260: } ! 261: break; ! 262: } ! 263: utime(outpath,NULL); ! 264: } ! 265: } ! 266: if(in != -1) ! 267: close(in); ! 268: if(out != -1) ! 269: close(out); ! 270: togglechat(cfg,nodenum,node,FALSE); ! 271: puttext(1,1,ti.screenwidth,ti.screenheight,buf); ! 272: window(ti.winleft,ti.wintop,ti.winright,ti.wintop); ! 273: gotoxy(ti.curx,ti.cury); ! 274: textattr(ti.attribute); ! 275: return(0); ! 276: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.