]> Git repositories of Nishi - tewi.git/commitdiff
fix stuff
authorNishi <nishi@nishi.boats>
Fri, 4 Oct 2024 03:13:36 +0000 (03:13 +0000)
committerNishi <nishi@nishi.boats>
Fri, 4 Oct 2024 03:13:36 +0000 (03:13 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@253 8739d7e6-ffea-ec47-b151-bdff447c6205

Common/log.c
Platform/watcom.mk
Server/Makefile
Server/config.c
Server/gui.c
Server/main.c
Server/server.c
config.h.tmpl
make-installer.sh

index a7b7963f5d367ee010a2304834ef445a4b219682..738fc13ef15ad424e3c595dba612fff31eab0b0e 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "cm_log.h"
 
+#include "../config.h"
 #include "cm_string.h"
 
 #include <time.h>
@@ -25,19 +26,30 @@ bool cm_do_log = false;
 
 #define LOGNAME_LENGTH 12
 
+#ifdef BUILD_GUI_VALID
+void AddLog(const char* str);
+#endif
+
 void cm_force_log(const char* log) {
        time_t t = time(NULL);
        struct tm* tm = localtime(&t);
        char date[513];
+       char* str;
        strftime(date, 512, "%a %b %d %H:%M:%S %Z %Y", tm);
 #ifdef _PSP
        pspDebugScreenPrintf("[%s] %s\n", date, log);
 #elif defined(__PPU__)
        tt_printf("[%s] %s\n", date, log);
+#elif defined(BUILD_GUI_VALID)
+       str = malloc(strlen(date) + strlen(log) + 3 + 1);
+       str[strlen(date) + strlen(log) + 3] = 0;
+       sprintf(str, "[%s] %s", date, log);
+       AddLog(str);
+       free(str);
 #else
        fprintf(logfile, "[%s] %s\n", date, log);
-#endif
        fflush(logfile);
+#endif
 }
 
 void cm_log(const char* name, const char* log, ...) {
index bf91582aaca5e98963a457c7885a16bfb2358e5c..f5bf848bbfb61e88fd7c3d10b81f2f7a2beabfb0 100644 (file)
@@ -13,4 +13,5 @@ EXEC = .exe
 STATIC = lib
 LIBSUF = .dll
 OBJ = obj
-SERVADD = wrc -bt=nt -i=$(WATCOM)/h/nt tewi.rc tewi.exe && wrc -bt=nt -i=$(WATCOM)/h/nt gui.rc tewi.exe
+REQOBJS = concat.rc
+SERVADD = wrc -bt=nt -i=$(WATCOM)/h/nt concat.rc tewi.exe
index 7ed240957ca36072c9555bb8f2a71e9f263c2d68..d408c01542ea0aa9dd1f15f5f94ff622530faabd 100644 (file)
@@ -45,22 +45,24 @@ tewi.pkg: tewi.self
 .c.$(OBJ):
        $(CC) $(CFLAGS) $(EXTCFLAGS) -c -o $@ $<
 
-tewi.res: tewi.rc ../Binary/tewi.ico
-       $(WINDRES) tewi.rc -O coff -o $@
+tewi.res: concat.rc ../Binary/tewi.ico
+       $(WINDRES) concat.rc -O coff -o $@
 
-tewi_bcc.res: tewi.rc ../Binary/tewi.ico
-       brc32 -r -fo$@ tewi.rc
+tewi_bcc.res: concat.rc ../Binary/tewi.ico
+       brc32 -r -fo$@ concat.rc
 
-gui.res: gui.rc gui.h
-       $(WINDRES) gui.rc -O coff -o $@
+gui.res: concat.rc gui.h
+       $(WINDRES) concat.rc -O coff -o $@
 
-gui_bcc.res: gui.rc gui.h
-       brc32 -r -fo$@ gui.rc
+gui_bcc.res: concat.rc gui.h
+       brc32 -r -fo$@ concat.rc
 
-vc6.res: tewi.rc gui.rc
-       cat tewi.rc gui.rc > concat.rc
+vc6.res: concat.rc
        rc /fo$@ concat.rc
        rm -f concat.rc
 
+concat.rc: tewi.rc gui.rc
+       cat tewi.rc gui.rc > concat.rc
+
 clean:
        rm -f *.o tewi *.exe *.res *.elf *.sfo *.pbp *.self *.pkg *.obj concat.rc
index f2bf9582f9242bf29a2acd621da41c11ad95ba30..bedda4ec10ed5abd82ed5d9ca186c5cec7fb8fc7 100644 (file)
@@ -131,6 +131,7 @@ int tw_config_read(const char* path) {
        int ln = 0;
        int ifbr = 0;
        int ignore = -1;
+       int portcount;
        FILE* f;
        cm_log("Config", "Reading %s", path);
        f = fopen(path, "r");
@@ -487,7 +488,12 @@ int tw_config_read(const char* path) {
                }
                free(line);
                fclose(f);
-               return stop;
+               for(portcount = 0; config.ports[portcount] != -1; portcount++);
+               if(portcount == 0){
+                       return 1;
+               }else{
+                       return stop;
+               }
        } else {
                cm_log("Config", "Could not open the file");
                return 1;
index 84f81a5abcb3d874a2860320edce3d033a998421..ba7d575717fab2a50427b9fab5250a6424c69a6d 100644 (file)
@@ -3,8 +3,13 @@
 #include "../config.h"
 
 #include "gui.h"
+#include "tw_server.h"
 
+#include <cm_log.h>
+
+#include <stdio.h>
 #include <windows.h>
+#include <process.h>
 #include <commctrl.h>
 
 HINSTANCE hInst;
@@ -14,15 +19,18 @@ HWND button_start;
 HWND button_stop;
 HWND button_about;
 HWND status;
+HFONT monospace;
 BOOL tewi_alive;
 BOOL was_starting;
 BOOL exiting;
+BOOL idle;
+extern FILE* logfile;
+extern int running;
 
 #define WINWIDTH(rc) (rc.right - rc.left)
 #define WINHEIGHT(rc) (rc.bottom - rc.top)
 
-#define DIALOG_X(n) (HIWORD(GetDialogBaseUnits()) * n)
-#define DIALOG_Y(n) (LOWORD(GetDialogBaseUnits()) * n)
+int startup(int argc, char** argv);
 
 void ShowBitmapSize(HWND hWnd, HDC hdc, const char* name, int x, int y, int w, int h){
        HBITMAP hBitmap = LoadBitmap(hInst, name);
@@ -44,6 +52,25 @@ void ShowBitmap(HWND hWnd, HDC hdc, const char* name, int x, int y){
        ShowBitmapSize(hWnd, hdc, name, x, y, 0, 0);
 }
 
+int max = 0;
+void AddLog(const char* str){
+       HDC hdc;
+       PAINTSTRUCT ps;
+       SIZE sz;
+
+       SendMessage(logarea, LB_ADDSTRING, 0, (LPARAM)str);
+
+       hdc = CreateCompatibleDC(NULL);
+       SelectObject(hdc, monospace);
+       GetTextExtentPoint32(hdc, str, strlen(str), &sz);
+       DeleteDC(hdc);
+       
+       if(max < sz.cx){
+               max = sz.cx;
+               SendMessage(logarea, LB_SETHORIZONTALEXTENT, max, 0);
+       }
+}
+
 LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
        if(msg == WM_COMMAND){
                if(LOWORD(wp) == IDOK) EndDialog(hWnd, IDOK);
@@ -62,19 +89,42 @@ LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
        }else if(msg == WM_CTLCOLORDLG || msg == WM_CTLCOLORSTATIC){
                HDC dc = (HDC)wp;
                SetBkMode(dc, TRANSPARENT);
-               return GetSysColorBrush(COLOR_MENU);
+               return (LRESULT)GetSysColorBrush(COLOR_MENU);
        }else{
                return FALSE;
        }
        return TRUE;
 }
 
-void StartTewi(void){
+void tewi_thread(void* ptr){
+       int st = startup(0, NULL);
+       was_starting = TRUE;
+       if(st == -1){
+               tewi_alive = TRUE;
+               idle = FALSE;
+       }else{
+               cm_force_log("Config error");
+               idle = FALSE;
+               _endthread();
+       }
+       running = 1;
+       tw_server_loop();
+       tewi_alive = FALSE;
        was_starting = TRUE;
+       idle = FALSE;
+       _endthread();
+}
+
+void StartTewi(void){
+       EnableWindow(button_start, FALSE);
+       EnableWindow(button_stop, FALSE);
+       _beginthread(tewi_thread, 0, NULL);
 }
 
 void StopTewi(void){
-       was_starting = TRUE;
+       EnableWindow(button_start, FALSE);
+       EnableWindow(button_stop, FALSE);
+       running = 0;
 }
 
 LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
@@ -118,6 +168,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
 
                InitCommonControls();
 
+               monospace = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
+
                status = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM, NULL, hWnd, GUI_STATUS);
                SendMessage(status, SB_SIMPLE, 0, 0);
                SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Welcome to Tewi HTTPd");
@@ -128,17 +180,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
                button_stop = CreateWindow("BUTTON", "S&top", WS_CHILD | WS_VISIBLE | WS_DISABLED | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 1, 100, 20, hWnd, (HMENU)GUI_BUTTON_STOP, hInst, NULL);
                button_about = CreateWindow("BUTTON", "&About", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 2, 100, 20, hWnd, (HMENU)GUI_BUTTON_ABOUT, hInst, NULL);
                button_about = CreateWindow("BUTTON", "E&xit", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, WINHEIGHT(rc) - WINHEIGHT(src) - 20, 100, 20, hWnd, (HMENU)GUI_BUTTON_EXIT, hInst, NULL);
-               logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL);
+               logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOSEL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL);
+
+               SendMessage(logarea, WM_SETFONT, (WPARAM)monospace, TRUE);
+
                SetTimer(hWnd, TIMER_WATCH_TEWI, 100, NULL);
        }else if(msg == WM_TIMER){
                if(wp == TIMER_WATCH_TEWI){
-                       if(tewi_alive){
+                       if(idle){
+                       }else if(tewi_alive){
                                if(was_starting){
                                        was_starting = FALSE;
                                        SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Started Tewi HTTPd");
                                }
                                EnableWindow(button_start, FALSE);
                                EnableWindow(button_stop, TRUE);
+                               idle = TRUE;
                        }else{
                                if(was_starting){
                                        was_starting = FALSE;
@@ -150,6 +207,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
                                        KillTimer(hWnd, TIMER_WATCH_TEWI);
                                        SendMessage(hWnd, WM_CLOSE, 0, 0);
                                }
+                               idle = TRUE;
                        }
                }
        }else if(msg == WM_PAINT){
@@ -171,7 +229,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
 }
 
 BOOL InitApp(void){
-       WNDCLASS wc;
+       WNDCLASSEX wc;
+       wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
@@ -182,7 +241,8 @@ BOOL InitApp(void){
        wc.hbrBackground = GetSysColorBrush(COLOR_MENU);
        wc.lpszMenuName = NULL;
        wc.lpszClassName = "tewihttpd";
-       return RegisterClass(&wc);
+       wc.hIconSm = LoadIcon(hInst, "TEWI");
+       return RegisterClassEx(&wc);
 }
 
 BOOL InitWindow(int nCmdShow){
@@ -190,7 +250,7 @@ BOOL InitWindow(int nCmdShow){
        RECT deskrc, rc;
        HWND hDeskWnd = GetDesktopWindow();
        GetWindowRect(hDeskWnd, &deskrc);
-       hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 200, NULL, 0, hInst, NULL);
+       hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 400, NULL, 0, hInst, NULL);
 
        if(!hWnd){
                return FALSE;
@@ -209,6 +269,8 @@ int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, in
        tewi_alive = FALSE;
        was_starting = FALSE;
        exiting = FALSE;
+       idle = TRUE;
+       logfile = stderr;
        if(!InitApp()){
                return FALSE;
        }
index 9d2965d4f7880aee139193631d290058d0ceeb47..6ccd60fdb9e4779e268b324ff0edbec94e4b77f4 100644 (file)
@@ -526,7 +526,7 @@ void show_png(void) {
 
 #endif
 
-#if !defined(BUILD_GUI) || !(defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__))
+#if !defined(BUILD_GUI_VALID)
 int main(int argc, char** argv) {
        int st;
        logfile = stderr;
@@ -796,7 +796,7 @@ int startup(int argc, char** argv) {
 #if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
        signal(SIGCHLD, SIG_IGN);
        signal(SIGPIPE, SIG_IGN);
-#else
+#elif !defined(BUILD_GUI)
        SetConsoleTitle(tw_server);
 #endif
        return -1;
index 190339e47a39ce862115a0f3415abc9282921299..ef24441678bd7a59fe8232ab956ce12c36b506e0 100644 (file)
@@ -1049,4 +1049,8 @@ void tw_server_loop(void) {
                        }
                }
        }
+       for(i = 0; i < sockcount; i++){
+               close_socket(sockets[i]);
+       }
+       cm_force_log("Server is down");
 }
index a5e8b095dc978b3aa34d67123b6d6dbc9fc93b33..4863f9e86f17a64a3780e8db5bb91e9c47abd759 100644 (file)
 #define SSL void
 #endif
 
+#if (defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)) && defined(USE_POLL)
+#define BUILD_GUI_VALID
+#endif
+
 #if (defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)) && defined(USE_POLL)
 #undef USE_POLL
 /* Force select(2) for Windows */
index ed61e382257bc924a78d5ed66db67d7e9437bcb9..c611712719bd5d96f031f7958b9f29c70f52e3d5 100755 (executable)
@@ -23,7 +23,7 @@ cp Server/tewi.exe tewi.exe
 cd Server
 ../Tool/genconf "C:/Tewi" modules dll > ../generated.conf
 ../Tool/itworks > ../itworks.html
-makensis /inputcharset utf8 -DVERSION=$VERSION -DONLY_EXEC install.nsi
+makensis -DVERSION=$VERSION -DONLY_EXEC install.nsi
 cp install.exe ../install.exe
 cd ..
 rm tewi.exe