1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675 |
- #define BUILDING_OPENDOORS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #include <limits.h>
- #include "OpenDoor.h"
- #ifdef ODPLAT_NIX
- #include <sys/types.h>
- #include <unistd.h>
- #include <signal.h>
- #include <fcntl.h>
- #include <errno.h>
- #endif
- #include "ODCore.h"
- #include "ODGen.h"
- #include "ODPlat.h"
- #include "ODCom.h"
- #include "ODKrnl.h"
- #include "ODScrn.h"
- #include "ODInQue.h"
- #include "ODInEx.h"
- #ifdef ODPLAT_WIN32
- #include "ODFrame.h"
- #endif
- #define REMOTE_INPUT_THREAD_PRIORITY OD_PRIORITY_NORMAL
- #define NO_CARRIER_THREAD_PRIORITY OD_PRIORITY_NORMAL
- #define NO_CARRIER_THREAD_SLEEP_TIME 6000
- #define TIME_UPDATE_THREAD_PRIORITY OD_PRIORITY_NORMAL
- #define TIME_UPDATE_THREAD_SLEEP_TIME 3000
- #define STATUS_UPDATE_PERIOD 3L
- #define CHAT_YIELD_PERIOD 25L
- #define KERNEL_FUNC_CHATTOGGLE 0x0001
- static void ODKrnlHandleReceivedChar(char chReceived, BOOL bFromRemote);
- static void ODKrnlTimeUpdate(void);
- static void ODKrnlChatCleanup(void);
- static void ODKrnlChatMode(void);
- #ifdef ODPLAT_NIX
- #ifdef USE_KERNEL_SIGNAL
- static void sig_run_kernel(int sig);
- static void sig_get_char(int sig);
- static void sig_no_carrier(int sig);
- #endif
- #endif
- #ifdef OD_MULTITHREADED
- DWORD OD_THREAD_FUNC ODKrnlRemoteInputThread(void *pParam);
- DWORD OD_THREAD_FUNC ODKrnlNoCarrierThread(void *pParam);
- DWORD OD_THREAD_FUNC ODKrnlTimeUpdateThread(void *pParam);
- DWORD OD_THREAD_FUNC ODKrnlChatThread(void *pParam);
- static void ODKrnlWaitForExclusiveControl(void);
- static void ODKrnlGiveUpExclusiveControl(void);
- #endif
- #ifdef OD_MULTITHREADED
- static tODThreadHandle hRemoteInputThread = NULL;
- static tODThreadHandle hNoCarrierThread = NULL;
- static tODThreadHandle hTimeUpdateThread = NULL;
- static tODThreadHandle hClientThread = NULL;
- static tODThreadHandle hChatThread = NULL;
- static BOOL bHaveExclusiveControl;
- static BOOL bChatActivatedInternally;
- #endif
- static BOOL bKernelActive = FALSE;
- static BOOL bWarnedAboutInactivity = FALSE;
- static INT16 nLastInactivitySetting = 0;
- static time_t nNextStatusUpdateTime;
- static INT nKrnlFuncPending;
- static BOOL bLastStatusSetting;
- static INT16 nChatOriginalAttrib;
- tODTimer RunKernelTimer;
- time_t nNextTimeDeductTime;
- char chLastControlKey = '\0';
- INT nArrowUseCount = 0;
- BOOL bForceStatusUpdate = FALSE;
- BOOL bIsShell;
- #ifdef OD_MULTITHREADED
- tODSemaphoreHandle hODActiveSemaphore = NULL;
- #endif
- tODResult ODKrnlInitialize(void)
- {
- #ifdef ODPLAT_NIX
- sigset_t block;
- #ifdef USE_KERNEL_SIGNAL
- struct sigaction act;
- struct itimerval itv;
- #endif
- #endif
- tODResult Result = kODRCSuccess;
-
- #ifdef ODPLAT_NIX
- #ifdef USE_KERNEL_SIGNAL
-
- act.sa_handler=sig_no_carrier;
-
- act.sa_flags=SA_RESETHAND|SA_RESTART;
- sigemptyset(&(act.sa_mask));
- sigaction(SIGHUP,&act,NULL);
-
- act.sa_handler=sig_run_kernel;
- act.sa_flags=SA_RESTART;
- sigemptyset(&(act.sa_mask));
- sigaction(SIGALRM,&act,NULL);
- itv.it_interval.tv_sec=0;
- itv.it_interval.tv_usec=10000;
- itv.it_value.tv_sec=0;
- itv.it_value.tv_usec=10000;
- setitimer(ITIMER_REAL,&itv,NULL);
-
-
- sigemptyset(&block);
- sigaddset(&block,SIGHUP);
- sigaddset(&block,SIGALRM);
- #if 0
- sigaddset(&block,SIGIO);
- #endif
- sigprocmask(SIG_UNBLOCK,&block,NULL);
- #else
- sigemptyset(&block);
- sigaddset(&block,SIGHUP);
- sigprocmask(SIG_BLOCK,&block,NULL);
- #endif
- #endif
-
- nNextStatusUpdateTime = time(NULL) + STATUS_UPDATE_PERIOD;
- nNextTimeDeductTime = time(NULL) + 60L;
- bLastStatusSetting = od_control.od_status_on = TRUE;
-
- nKrnlFuncPending = 0;
-
- bKernelActive = FALSE;
- #ifdef OD_MULTITHREADED
-
- bHaveExclusiveControl = FALSE;
-
- hClientThread = ODThreadGetCurrent();
-
- if(hODActiveSemaphore == NULL)
- {
- Result = ODSemaphoreAlloc(&hODActiveSemaphore, 0, INT_MAX);
- if(Result != kODRCSuccess) return(Result);
- }
-
- if(od_control.baud != 0)
- {
- Result = ODThreadCreate(&hRemoteInputThread, ODKrnlRemoteInputThread,
- NULL);
- if(Result != kODRCSuccess) return(Result);
- ODThreadSetPriority(hRemoteInputThread, REMOTE_INPUT_THREAD_PRIORITY);
- }
-
-
- if(od_control.baud != 0)
- {
- Result = ODThreadCreate(&hNoCarrierThread, ODKrnlNoCarrierThread, NULL);
- if(Result != kODRCSuccess) return(Result);
- ODThreadSetPriority(hNoCarrierThread, NO_CARRIER_THREAD_PRIORITY);
- }
-
- Result = ODThreadCreate(&hTimeUpdateThread, ODKrnlTimeUpdateThread, 0);
- if(Result != kODRCSuccess) return(Result);
- ODThreadSetPriority(hTimeUpdateThread, TIME_UPDATE_THREAD_PRIORITY);
- #endif
-
- return(Result);
- }
- void ODKrnlShutdown(void)
- {
- if(bKernelActive) return;
- #ifdef OD_MULTITHREADED
- #if defined(OD_DIAGNOSTICS) && defined(ODPLAT_WIN32)
- if(od_control.od_internal_debug)
- MessageBox(NULL, "Terminating remote input thread", "OpenDoors Diagnostics", MB_OK);
- #endif
-
- if(hRemoteInputThread != NULL) ODThreadTerminate(hRemoteInputThread);
- #if defined(OD_DIAGNOSTICS) && defined(ODPLAT_WIN32)
- if(od_control.od_internal_debug)
- MessageBox(NULL, "Terminating carrier detection", "OpenDoors Diagnostics", MB_OK);
- #endif
-
- if(hNoCarrierThread != NULL) ODThreadTerminate(hNoCarrierThread);
- #if defined(OD_DIAGNOSTICS) && defined(ODPLAT_WIN32)
- if(od_control.od_internal_debug)
- MessageBox(NULL, "Terminating time update thread", "OpenDoors Diagnostics", MB_OK);
- #endif
-
- if(hTimeUpdateThread != NULL) ODThreadTerminate(hTimeUpdateThread);
- #if defined(OD_DIAGNOSTICS) && defined(ODPLAT_WIN32)
- if(od_control.od_internal_debug)
- MessageBox(NULL, "Releasing activation semaphore", "OpenDoors Diagnostics", MB_OK);
- #endif
- #endif
- }
- ODAPIDEF void ODCALL od_kernel(void)
- {
- #ifndef OD_MULTITHREADED
- char ch;
- #ifdef ODPLAT_DOS
- WORD wKey;
- BYTE btShiftStatus;
- char *pszShellName;
- #endif
- BOOL bCarrier;
- #endif
-
- TRACE(TRACE_API, "od_kernel()");
-
- if(!bODInitialized) od_init();
-
-
-
- if(bKernelActive) return;
- OD_API_ENTRY();
-
- bKernelActive = TRUE;
-
- if(od_control.od_ker_exec != NULL)
- {
- (*od_control.od_ker_exec)();
- }
-
-
- #ifndef OD_MULTITHREADED
-
-
- if(od_control.baud != 0)
- {
- #ifndef USE_KERNEL_SIGNAL
-
-
- if(!(od_control.od_disable&DIS_CARRIERDETECT))
- {
- ODComCarrier(hSerialPort, &bCarrier);
- if(!bCarrier)
- {
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_NOCARRIER);
- }
- }
- #endif
-
-
- while(ODComGetByte(hSerialPort, &ch, FALSE) == kODRCSuccess)
- {
- ODKrnlHandleReceivedChar(ch, TRUE);
- }
- }
- #ifdef ODPLAT_DOS
- check_keyboard_again:
- if(nKrnlFuncPending && !bShellChatActive)
- {
- if(nKrnlFuncPending & KERNEL_FUNC_CHATTOGGLE)
- {
- nKrnlFuncPending &=~ KERNEL_FUNC_CHATTOGGLE;
- goto chat_pressed;
- }
- }
-
-
- if(od_control.od_disable & DIS_SYSOP_KEYS
- || od_control.od_silent_mode)
- {
- goto after_key_check;
- }
- ASM mov ah, 1
- ASM push si
- ASM push di
- ASM int 0x16
- ASM jnz key_waiting
- ASM pop di
- ASM pop si
- ASM jmp after_key_check
- key_waiting:
- ASM mov ah, 0
- ASM int 0x16
- ASM mov wKey, ax
- ASM mov ah, 2
- ASM int 0x16
- ASM mov btShiftStatus, al
- ASM pop di
- ASM pop si
- if(nArrowUseCount > 0 && (wKey == 0x4800 || wKey == 0x5000)
- && !(btShiftStatus & 2))
- {
-
- if(od_control.od_local_input != NULL)
- {
- (*od_control.od_local_input)(wKey);
- }
-
- ODKrnlHandleLocalKey(wKey);
- }
-
- else if(wKey == od_control.key_hangup)
- {
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_HANGUP);
- }
-
- else if(wKey == od_control.key_drop2bbs)
- {
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_DROPTOBBS);
- }
- else if(wKey == od_control.key_dosshell)
- {
- if(!bShellChatActive)
- {
- if(pfLogWrite != NULL)
- (*pfLogWrite)(6);
-
- if(od_control.od_cbefore_shell != NULL)
- {
-
- bShellChatActive = TRUE;
- (*od_control.od_cbefore_shell)();
- bShellChatActive = FALSE;
- }
- if(od_control.od_before_shell != NULL)
- od_disp_str(od_control.od_before_shell);
- if((pszShellName = (char *)getenv("COMSPEC")) == NULL)
- {
- pszShellName = (char *)"COMMAND.COM";
- }
- bIsShell = TRUE;
- od_spawnvpe(P_WAIT, pszShellName, NULL, NULL);
- bIsShell = FALSE;
- if(od_control.od_after_shell != NULL)
- od_disp_str(od_control.od_after_shell);
-
- if(od_control.od_cafter_shell != NULL)
- {
-
- bShellChatActive = TRUE;
- (*od_control.od_cafter_shell)();
- bShellChatActive = FALSE;
- }
- if(pfLogWrite != NULL)
- (*pfLogWrite)(7);
- }
- }
-
- else if(wKey == od_control.key_chat)
- {
- chat_pressed:
- if(!bShellChatActive || od_control.od_chat_active)
- {
-
- if(od_control.od_chat_active)
- {
-
- ODKrnlEndChatMode();
- }
-
- else
- {
-
- bKernelActive = FALSE;
-
- ODKrnlChatMode();
-
- bKernelActive = TRUE;
- }
- }
- else
- {
- if(nKrnlFuncPending & KERNEL_FUNC_CHATTOGGLE)
- {
- nKrnlFuncPending &= ~KERNEL_FUNC_CHATTOGGLE;
- }
- else
- {
- nKrnlFuncPending |= KERNEL_FUNC_CHATTOGGLE;
- }
- }
- }
-
- else if(wKey == od_control.key_sysopnext)
- {
-
- od_control.sysop_next = !od_control.sysop_next;
-
- goto statup;
- }
-
- else if((wKey&0xff) == 27 && od_control.od_chat_active)
- {
-
- od_control.od_chat_active = FALSE;
- }
-
- else if(wKey == od_control.key_lockout)
- {
-
- od_control.user_security = 0;
-
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_HANGUP);
- }
-
- else if(wKey == od_control.key_keyboardoff)
- {
-
- od_control.od_user_keyboard_on =! od_control.od_user_keyboard_on;
-
- goto statup;
- }
-
- else if(wKey == od_control.key_moretime)
- {
-
- if(od_control.user_timelimit < 1440)
- {
-
- ++od_control.user_timelimit;
- }
-
- goto statup;
- }
-
- else if(wKey == od_control.key_lesstime)
- {
-
- if(od_control.user_timelimit > 0)
- {
-
- --od_control.user_timelimit;
- }
-
- goto statup;
- }
- else
- {
- for(ch = 0; ch < 9; ++ch)
- {
- if(wKey == od_control.key_status[ch])
- {
- if(btCurrentStatusLine != ch && od_control.od_status_on)
- {
- od_set_statusline(ch);
- }
- goto check_keyboard_again;
- }
- }
-
- for(ch=0; ch<od_control.od_num_keys; ++ch)
- {
-
- if(wKey == (WORD)od_control.od_hot_key[ch])
- {
-
- od_control.od_last_hot = wKey;
-
- (*pfCurrentPersonality)(21);
-
- if(od_control.od_hot_function[ch] != NULL)
- {
-
- (*od_control.od_hot_function[ch])();
- }
-
- break;
- }
- }
-
- if(ch >= od_control.od_num_keys)
- {
-
- if(od_control.od_local_input != NULL)
- {
- (*od_control.od_local_input)(wKey);
- }
-
- ODKrnlHandleLocalKey(wKey);
- }
- }
- goto check_keyboard_again;
- after_key_check:
-
- if(bLastStatusSetting != od_control.od_status_on)
- {
-
- od_set_statusline(0);
- }
- bLastStatusSetting = od_control.od_status_on;
- if(od_control.od_update_status_now)
- {
- od_set_statusline(btCurrentStatusLine);
- od_control.od_update_status_now = FALSE;
- }
-
- if(nNextStatusUpdateTime < time(NULL) || bForceStatusUpdate)
- {
- statup:
- nNextStatusUpdateTime = time(NULL) + STATUS_UPDATE_PERIOD;
-
- bForceStatusUpdate = FALSE;
- if(od_control.od_status_on && btCurrentStatusLine != 8)
- {
-
- ODStoreTextInfo();
-
- ODScrnSetBoundary(1, 1, 80, 25);
- ODScrnEnableCaret(FALSE);
- (*pfCurrentPersonality)((BYTE)(10 + btCurrentStatusLine));
- ODRestoreTextInfo();
- ODScrnEnableCaret(TRUE);
- }
- }
- #endif
- ODKrnlTimeUpdate();
- ODTimerStart(&RunKernelTimer, 250);
- OD_API_EXIT();
- bKernelActive = FALSE;
- #endif
- }
- void ODKrnlHandleLocalKey(WORD wKeyCode)
- {
-
- if(!(od_control.od_disable & DIS_LOCAL_INPUT))
- {
- if((wKeyCode & 0xff) == 0)
- {
- ODKrnlHandleReceivedChar('\0', FALSE);
- ODKrnlHandleReceivedChar((char)(wKeyCode >> 8), FALSE);
- }
- else
- {
- ODKrnlHandleReceivedChar((char)wKeyCode, FALSE);
- }
- }
- }
- static void ODKrnlHandleReceivedChar(char chReceived, BOOL bFromRemote)
- {
- tODInputEvent InputEvent;
-
-
- if(bFromRemote && !od_control.od_user_keyboard_on)
- {
- return;
- }
-
- InputEvent.EventType = EVENT_CHARACTER;
- InputEvent.bFromRemote = bFromRemote;
- InputEvent.chKeyPress = chReceived;
- ODInQueueAddEvent(hODInputQueue, &InputEvent);
-
- switch(chReceived)
- {
- case 's':
- case 'S':
- case 3:
- case 11:
- case 0x18:
- chLastControlKey = 's';
- break;
- case 'p':
- case 'P':
- chLastControlKey = 'p';
- }
- }
- static void ODKrnlTimeUpdate(void)
- {
- time_t CurrentTime;
- static char szTemp[80];
-
- CurrentTime = time(NULL);
-
- if(nLastInactivitySetting != od_control.od_inactivity)
- {
-
- if(nLastInactivitySetting == 0)
- {
-
- ODInQueueResetLastActivity(hODInputQueue);
- }
-
- nLastInactivitySetting = od_control.od_inactivity;
- }
-
- if((ODInQueueGetLastActivity(hODInputQueue) + od_control.od_inactivity)
- < CurrentTime)
- {
-
- if(od_control.od_inactivity != 0 && !od_control.od_disable_inactivity)
- {
- if(od_control.od_time_msg_func == NULL)
- {
- od_disp_str(od_control.od_inactivity_timeout);
- }
- else
- {
- (*od_control.od_time_msg_func)(od_control.od_inactivity_timeout);
- }
-
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_INACTIVITY);
- }
- }
-
- else if(ODInQueueGetLastActivity(hODInputQueue) + od_control.od_inactivity
- < CurrentTime + od_control.od_inactive_warning)
- {
- if(!bWarnedAboutInactivity && od_control.od_inactivity != 0
- && !od_control.od_disable_inactivity)
- {
-
- if(od_control.od_time_msg_func == NULL)
- {
- od_disp_str(od_control.od_inactivity_warning);
- }
- else
- {
- (*od_control.od_time_msg_func)(od_control.od_inactivity_warning);
- }
-
- bWarnedAboutInactivity = TRUE;
- }
- }
- else
- {
-
- bWarnedAboutInactivity = FALSE;
- }
-
- if(od_control.od_chat_active)
- {
-
- nNextTimeDeductTime = time(NULL) + 60;
- }
-
- if(CurrentTime >= nNextTimeDeductTime)
- {
-
-
- nNextTimeDeductTime += 60;
-
- bForceStatusUpdate = TRUE;
-
- --od_control.user_timelimit;
-
-
- if(od_control.user_timelimit <= 3 &&
- od_control.user_timelimit > 0 &&
- !(od_control.od_disable & DIS_TIMEOUT))
- {
-
- sprintf(szTemp, od_control.od_time_warning,
- od_control.user_timelimit);
- if(od_control.od_time_msg_func == NULL)
- {
- od_disp_str(szTemp);
- }
- else
- {
- (*od_control.od_time_msg_func)(szTemp);
- }
- }
- #ifdef ODPLAT_WIN32
- ODFrameUpdateTimeDisplay();
- #endif
- }
-
- if(od_control.user_timelimit <= 0
- && !(od_control.od_disable & DIS_TIMEOUT))
- {
-
- if(od_control.od_time_msg_func == NULL)
- {
- od_disp_str(od_control.od_no_time);
- }
- else
- {
- (*od_control.od_time_msg_func)(od_control.od_no_time);
- }
-
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_TIMEOUT);
- }
- }
- void ODKrnlForceOpenDoorsShutdown(BYTE btReasonForShutdown)
- {
- BOOL bHangup;
- #ifdef OD_MULTITHREADED
-
-
-
-
- ODKrnlWaitForExclusiveControl();
- #endif
- bKernelActive = TRUE;
-
- if(btReasonForShutdown == ERRORLEVEL_HANGUP
- || btReasonForShutdown == ERRORLEVEL_INACTIVITY)
- {
- bHangup = TRUE;
- }
- else
- {
- bHangup = FALSE;
- }
-
- btExitReason = btReasonForShutdown - 1;
-
- if(od_control.od_errorlevel[0])
- {
- od_exit(od_control.od_errorlevel[btReasonForShutdown], bHangup);
- }
-
- else
- {
- od_exit(btReasonForShutdown - 1, bHangup);
- }
- }
- #ifdef OD_MULTITHREADED
- DWORD OD_THREAD_FUNC ODKrnlRemoteInputThread(void *pParam)
- {
- char chReceived;
-
- for(;;)
- {
-
-
- ODComGetByte(hSerialPort, &chReceived, TRUE);
-
-
- ODKrnlHandleReceivedChar(chReceived, TRUE);
- }
- return(0);
- }
- DWORD OD_THREAD_FUNC ODKrnlNoCarrierThread(void *pParam)
- {
-
-
- for(;;)
- {
-
- ODComWaitEvent(hSerialPort, kNoCarrier);
-
-
- if(!(od_control.od_disable&DIS_CARRIERDETECT)) break;
-
-
-
-
- od_sleep(NO_CARRIER_THREAD_SLEEP_TIME);
- }
-
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_NOCARRIER);
- return(0);
- }
- DWORD OD_THREAD_FUNC ODKrnlTimeUpdateThread(void *pParam)
- {
-
- for(;;)
- {
-
- od_sleep(TIME_UPDATE_THREAD_SLEEP_TIME);
-
- ODKrnlTimeUpdate();
- }
- return(0);
- }
- static void ODKrnlWaitForExclusiveControl(void)
- {
-
- if(bHaveExclusiveControl) return;
-
- ODSemaphoreDown(hODActiveSemaphore, OD_NO_TIMEOUT);
-
- ASSERT(hClientThread != NULL);
- ODThreadSuspend(hClientThread);
-
- bHaveExclusiveControl = TRUE;
- }
- static void ODKrnlGiveUpExclusiveControl(void)
- {
-
-
- if(!bHaveExclusiveControl) return;
-
- ASSERT(hClientThread != NULL);
- ODThreadResume(hClientThread);
-
-
- ODSemaphoreUp(hODActiveSemaphore, 1);
-
- bHaveExclusiveControl = FALSE;
- }
- #endif
- BOOL bChatted;
- BOOL bSysopColor;
- #ifdef OD_MULTITHREADED
- DWORD OD_THREAD_FUNC ODKrnlChatThread(void *pParam)
- {
- BOOL bTriggeredInsideOpenDoors = bChatActivatedInternally;
-
-
- if(bTriggeredInsideOpenDoors)
- {
- ODKrnlWaitForExclusiveControl();
- }
-
- ODKrnlChatMode();
-
-
- if(bTriggeredInsideOpenDoors)
- {
- ODKrnlGiveUpExclusiveControl();
- }
-
- return(0);
- }
- tODResult ODKrnlStartChatThread(BOOL bTriggeredInternally)
- {
- tODResult Result;
- bChatActivatedInternally = bTriggeredInternally;
- Result = ODThreadCreate(&hChatThread, ODKrnlChatThread, NULL);
- if(Result != kODRCSuccess)
- {
- return(Result);
- }
-
-
- od_control.od_chat_active = TRUE;
- #ifdef ODPLAT_WIN32
-
- ODFrameUpdateCmdUI();
- #endif
- return(kODRCSuccess);
- }
- #endif
- void ODKrnlEndChatMode(void)
- {
- #ifdef OD_MULTITHREADED
-
- ODThreadTerminate(hChatThread);
-
- ODKrnlChatCleanup();
- #else
-
- od_control.od_chat_active = FALSE;
- #endif
- }
- ODAPIDEF void ODCALL od_chat(void)
- {
-
- TRACE(TRACE_API, "od_chat()");
-
- od_control.od_chat_active = TRUE;
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
- #ifdef OD_MULTITHREADED
-
-
-
- if(ODKrnlStartChatThread(FALSE) != kODRCSuccess)
- {
- od_control.od_error = ERR_GENERALFAILURE;
- OD_API_EXIT();
- }
-
- ODThreadWaitForExit(hChatThread);
-
- hChatThread = NULL;
- #else
-
-
- ODKrnlChatMode();
- #endif
- OD_API_EXIT();
- }
- static void ODKrnlChatMode(void)
- {
- BYTE chKeyPressed;
- char szCurrentWord[79];
- BYTE btWordLength = 0;
- BYTE btCurrentColumn = 0;
- char *pchCurrent;
- BYTE btCount;
- #ifndef OD_MULTITHREADED
- tODTimer Timer;
- #endif
-
- szCurrentWord[0] = '\0';
-
- nChatOriginalAttrib = od_control.od_cur_attrib;
-
- bChatted = TRUE;
-
-
- od_control.user_wantchat = FALSE;
- #ifdef ODPLAT_WIN32
- ODFrameUpdateWantChat();
- #endif
- bForceStatusUpdate = TRUE;
- CALL_KERNEL_IF_NEEDED();
-
- od_control.od_chat_active = TRUE;
-
- if(od_control.od_cbefore_chat!=NULL)
- {
- bShellChatActive = TRUE;
- (*od_control.od_cbefore_chat)();
- bShellChatActive = FALSE;
-
- if(!od_control.od_chat_active) goto cleanup;
- }
-
- od_set_attrib(od_control.od_chat_color1);
- if(od_control.od_before_chat != NULL)
- od_disp_str(od_control.od_before_chat);
-
- bSysopColor = TRUE;
-
-
- if(pfLogWrite != NULL)
- {
- (*pfLogWrite)(9);
- }
- #ifndef OD_MULTITHREADED
-
- ODTimerStart(&Timer, CHAT_YIELD_PERIOD);
- #endif
-
- while(od_control.od_chat_active)
- {
-
- #ifdef OD_MULTITHREADED
- chKeyPressed = od_get_key(TRUE);
- #else
- chKeyPressed = od_get_key(FALSE);
- #endif
-
- if((od_control.od_last_input && !bSysopColor)
- || (!od_control.od_last_input && bSysopColor))
- {
-
- if(od_control.od_last_input)
- {
-
- od_set_attrib(od_control.od_chat_color1);
- }
- else
- {
-
- od_set_attrib(od_control.od_chat_color2);
- }
-
- bSysopColor = od_control.od_last_input;
- }
-
- if(chKeyPressed >= 32)
- {
-
- od_putch(chKeyPressed);
-
-
- if(chKeyPressed == 32)
- {
- btWordLength = 0;
- szCurrentWord[0] = 0;
- }
-
-
- else if(btWordLength < 70)
- {
- szCurrentWord[btWordLength++] = chKeyPressed;
- szCurrentWord[btWordLength] = '\0';
- }
-
-
- if(btCurrentColumn < 75)
- {
- ++btCurrentColumn;
- }
-
- else
- {
-
- if(btWordLength < 70 && btWordLength > 0)
- {
-
- pchCurrent = (char *)szODWorkString;
- for(btCount = 0; btCount < btWordLength; ++btCount)
- {
- *(pchCurrent++) = 8;
- }
- for(btCount = 0; btCount < btWordLength; ++btCount)
- {
- *(pchCurrent++) = ' ';
- }
- *pchCurrent = '\0';
-
- od_disp_str(szODWorkString);
-
- od_disp_str("\n\r");
-
- od_disp_str(szCurrentWord);
-
- btCurrentColumn = btWordLength;
- }
-
-
- else
- {
-
- od_disp_str("\n\r");
-
- btCurrentColumn = 0;
- }
-
- btWordLength = 0;
- szCurrentWord[0] = 0;
- }
- }
-
- else if(chKeyPressed == 8)
- {
-
- od_disp_str(szBackspaceWithDelete);
-
-
- if(btWordLength > 0)
- {
- szCurrentWord[--btWordLength] = '\0';
- }
-
- if(btCurrentColumn > 0) --btCurrentColumn;
- }
-
- else if(chKeyPressed == 13)
- {
-
- od_disp_str("\n\r");
-
- btWordLength = 0;
- szCurrentWord[0] = 0;
-
- btCurrentColumn = 0;
- }
-
- else if(chKeyPressed == 27 && od_control.od_last_input)
- {
-
- goto cleanup;
- }
- #ifndef OD_MULTITHREADED
-
- else if(ODTimerElapsed(&Timer))
- {
- od_sleep(0);
-
-
- ODTimerStart(&Timer, CHAT_YIELD_PERIOD);
- }
- #endif
- }
- cleanup:
- ODKrnlChatCleanup();
- }
- static void ODKrnlChatCleanup(void)
- {
- od_set_attrib(od_control.od_chat_color1);
-
- if(od_control.od_after_chat != NULL)
- {
- od_disp_str(od_control.od_after_chat);
- }
-
- if(od_control.od_cafter_chat != NULL)
- {
- bShellChatActive = TRUE;
- (*od_control.od_cafter_chat)();
- bShellChatActive = FALSE;
- }
-
-
- if(pfLogWrite != NULL)
- {
- (*pfLogWrite)(10);
- }
-
- od_set_attrib(nChatOriginalAttrib);
-
- od_control.od_chat_active = FALSE;
- #ifdef ODPLAT_WIN32
-
- ODFrameUpdateCmdUI();
- #endif
- #ifdef OD_MULTITHREADED
- if(bChatActivatedInternally)
- {
- ODKrnlGiveUpExclusiveControl();
- }
- #endif
- }
- #ifdef ODPLAT_NIX
- #ifdef USE_KERNEL_SIGNAL
- static void sig_run_kernel(int sig)
- {
- od_kernel();
- }
- static void sig_get_char(int sig)
- {
- static char ch;
-
-
- while(ODComGetByte(hSerialPort, &ch, FALSE) == kODRCSuccess)
- {
- ODKrnlHandleReceivedChar(ch, TRUE);
- }
- }
- static void sig_no_carrier(int sig)
- {
- if(od_control.baud != 0 && )
- {
- if(!(od_control.od_disable&DIS_CARRIERDETECT))
- ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_NOCARRIER);
- }
- }
- #endif
- #endif
|