123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- #include "OpenDoor.h"
- #include <string.h>
- #define STANDALONE
- void fullscreen_chat(void);
- void chat_new_line(void);
- void display_shell_window(void);
- void remove_shell_window(void);
- #ifdef ODPLAT_WIN32
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpszCmdLine, int nCmdShow)
- #else
- int main(int argc, char *argv[])
- #endif
- {
-
- #ifdef ODPLAT_WIN32
- od_control.od_cmd_show = nCmdShow;
- od_parse_cmd_line(lpszCmdLine);
- #else
- od_parse_cmd_line(argc, argv);
- #endif
- #ifdef STANDALONE
- od_init();
- fullscreen_chat();
- #else
-
- od_control.od_cbefore_chat=fullscreen_chat;
- od_printf("Press [Enter] to exit door, or invoke chat mode.\n\r");
- od_get_answer("\n\r");
- #endif
- od_exit(0, FALSE);
- return(0);
- }
-
- char window_colour[2]={0x0b,0x0c};
- char bar_colour=0x70;
- char top_line[2]={13,1};
- char bottom_line[2]={23,11};
- char bar_line=12;
- char scroll_distance=2;
- char shell_window_title=0x1a;
- char shell_window_boarder=0x1f;
- char shell_window_text=0x1b;
- int cursor_window;
- char current_word[2][81];
- int word_length[2];
- int cursor_col[2];
- int cursor_line[2];
- unsigned char key;
- int old_chat_key;
- void *shell_window;
- char *before_shell_text;
- char *after_shell_text;
- #ifndef STANDALONE
- char screen_buffer[4004];
- #endif
-
- void fullscreen_chat(void)
- {
- cursor_window=0;
- word_length[0]=word_length[1]=0;
- cursor_col[0]=cursor_col[1]=1;
- cursor_line[0]=top_line[0];
- cursor_line[1]=top_line[1];
-
- if(!od_control.user_ansi && !od_control.user_avatar)
- {
- #ifdef STANDALONE
- od_chat();
- #endif
- return;
- }
- od_control.od_cbefore_shell=display_shell_window;
- od_control.od_cafter_shell=remove_shell_window;
- before_shell_text=od_control.od_before_shell;
- after_shell_text=od_control.od_after_shell;
- od_control.od_before_shell=NULL;
- od_control.od_after_shell=NULL;
- od_control.od_chat_active=TRUE;
- #ifdef STANDALONE
- old_chat_key=od_control.key_chat;
- od_control.key_chat=0;
- #else
- od_save_screen(screen_buffer);
- #endif
-
- od_set_attrib(window_colour[0]);
- od_clr_scr();
- od_set_cursor(bar_line,1);
- od_set_attrib(bar_colour);
- od_clr_line();
- od_set_cursor(bar_line,67);
- od_printf("Ctrl-A: Clear");
- od_set_cursor(bar_line,1);
- od_printf(" Top : %-.28s Bottom : %-.28s ",
- od_control.sysop_name, od_control.user_name);
- od_set_cursor(top_line[0],1);
- od_set_attrib(window_colour[0]);
-
- for(;;)
- {
- do
- {
- key=(char)od_get_key(FALSE);
-
- if((key==27 && od_control.od_last_input==1)
- || !od_control.od_chat_active)
- {
- od_set_attrib(0x07);
- od_clr_scr();
- od_control.od_cbefore_shell=NULL;
- od_control.od_cafter_shell=NULL;
- od_control.od_before_shell=before_shell_text;
- od_control.od_after_shell=after_shell_text;
- #ifdef STANDALONE
- od_control.key_chat=old_chat_key;
- #else
- od_control.od_chat_active=FALSE;
- od_restore_screen(screen_buffer);
- #endif
- return;
- }
- } while(key==0);
-
- if(od_control.od_last_input!=cursor_window)
- {
- cursor_window=od_control.od_last_input;
-
- od_set_cursor(cursor_line[cursor_window],cursor_col[cursor_window]);
- od_set_attrib(window_colour[cursor_window]);
- }
- if(key==13 || key==10)
- {
- word_length[cursor_window]=0;
- chat_new_line();
- }
- else if(key==8)
- {
- if(cursor_col[cursor_window] > 1)
- {
- --cursor_col[cursor_window];
- if(word_length[cursor_window] > 0) --word_length[cursor_window];
- od_printf("\b \b");
- }
- }
- else if(key==32)
- {
- word_length[cursor_window]=0;
- if(cursor_col[cursor_window]==79)
- chat_new_line();
- else
- {
- ++cursor_col[cursor_window];
- od_putch(32);
- }
- }
- else if(key==1)
- {
- od_scroll(1,top_line[cursor_window],79,bottom_line[cursor_window],
- bottom_line[cursor_window]-top_line[cursor_window]+1,0);
- word_length[cursor_window]=0;
- cursor_col[cursor_window]=1;
- cursor_line[cursor_window]=top_line[cursor_window];
- od_set_cursor(cursor_line[cursor_window],cursor_col[cursor_window]);
- }
- else if(key>32)
- {
- if(cursor_col[cursor_window]==79)
- {
-
- if(word_length[cursor_window]>0 && word_length[cursor_window]<78)
- {
-
- od_set_cursor(cursor_line[cursor_window],
- cursor_col[cursor_window]-word_length[cursor_window]);
- od_clr_line();
- chat_new_line();
-
- od_disp(current_word[cursor_window],word_length[cursor_window],
- TRUE);
- cursor_col[cursor_window]+=word_length[cursor_window];
- }
- else
- {
- chat_new_line();
- word_length[cursor_window]=0;
- }
- }
-
-
- if(strlen(current_word[cursor_window])<79)
- current_word[cursor_window][word_length[cursor_window]++]=key;
-
- ++cursor_col[cursor_window];
- od_putch(key);
- }
- }
- }
-
- void chat_new_line(void)
- {
- if(cursor_line[cursor_window]==bottom_line[cursor_window])
- {
- od_scroll(1,top_line[cursor_window],79, bottom_line[cursor_window],
- scroll_distance, 0);
- cursor_line[cursor_window]-=(scroll_distance - 1);
- }
- else
- {
- ++cursor_line[cursor_window];
- }
-
- od_set_cursor(cursor_line[cursor_window],cursor_col[cursor_window]=1);
- od_set_attrib(window_colour[cursor_window]);
- }
- void display_shell_window(void)
- {
- if((shell_window=od_window_create(17,9,63,15,"DOS Shell",
- shell_window_boarder, shell_window_title,
- shell_window_text, 0))==NULL) return;
- od_set_attrib(shell_window_text);
- od_set_cursor(11,26);
- od_printf("The Sysop has shelled to DOS");
- od_set_cursor(13,21);
- od_printf("He/She will return in a few moments...");
- }
- void remove_shell_window(void)
- {
- od_window_remove(shell_window);
- od_set_cursor(cursor_line[cursor_window],cursor_col[cursor_window]);
- od_set_attrib(window_colour[cursor_window]);
- }
|