#include #include #include #include #include "desqview.hpp" #include "proboard.hpp" const MAX_LOCK_TRIES = 500; const LOCK_PAUSE = 10; static char *lock_err_msg = "CHAT FILE LOCKING ERROR (%d)"; class chatdata { int online; int head,tail; char data[240]; static File f[2]; static int node[2]; public: chatdata(int n1,int n2); ~chatdata(); void queue(char x); int getnext(char *); }; File chatdata::f[2]; int chatdata::node[2]; chatdata::chatdata(int n1,int n2) { node[0] = n1; node[1] = n2; if(!f[0].open(form("%sCHAT%d.DAT",syspath,node[0]),fmode_rw | fmode_shared | fmode_copen)) return; memset(this,0,sizeof(*this)); f[0].write(this,sizeof(*this)); time_t t = time(NULL); for(;;) { if(f[1].open(form("%sCHAT%d.DAT",syspath,node[1]),fmode_rw | fmode_shared)) break; if((time(NULL)-t)>20) { LOG("File sharing error during chat!"); break; } } } chatdata::~chatdata() { f[0].close(); f[1].close(); } void chatdata::queue(char c) { for(int i=0;icfg.numnodes || node2<=0) return; user_online uo; uo.setstatus(UO_BROWSING); switch(uo.chatreq(node2)) { case 1: uo.setstatus(UO_BUSY,node2); case 2: io << S_MCHAT_NODE_IS_NOT_AVAILABLE << "\n\n" << S_PRESS_ENTER_TO_CONTINUE; return; } io << S_MCHAT_STARTED << "\n\n\xFF"; multilinechat(node2); uo.setstatus(UO_BROWSING); io << "\n\n" << S_MULTILINE_CHAT_ENDED << ' ' << S_PRESS_ENTER_TO_CONTINUE; } void multilinechat(int n) { int node1,node2; char buffer[240]; user_online uo; int last=0; String s; node1 = node_number; node2 = n; LOG(1,"Multiline chat started"); chatdata cd(node1,node2); uo.setstatus(UO_CHATTING); for(int i=0;;i++) { char x; if((x=io.readkey())!=0) { if(x<8) continue; if(x==27) break; if(last!=1) { if(avatar) io << "\x16\x01\x0B\xFF"; else if(ansi_mode) io << "\xFF"; } last=1; if(x=='\t') x=' '; if(x!=8) io << x << char(0xFF); switch(x) { case 8: if(s.len()>0) { s[s.len()-1]=0; io << "\b \b\xFF"; } break; case 13: io << '\n' << char(255); s=""; break; default: s << (char)x; } if(s.len()>78) { String wrap; int l = wordwrap(s,wrap,78); for(int i=0;i5) { i = uo.getstatus(node2); if(i==UO_OFFLINE) { io << "\n\n" << S_MCHAT_OTHER_NODE_HUNG_UP << '\xFF'; return; } i=0; } int count = cd.getnext(buffer); for(int i=0;i0) { s[s.len()-1]=0; io << "\b \b\xFF"; } break; case 13: io << "\n\xFF"; s = ""; break; default: s << (char)x; } if(s.len()>78) { String wrap; int l=wordwrap(s,wrap,78); for(int i=0;i