#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <winsock.h>
#include <richedit.h>
#include "NanoMud.h"
#include <assert.h>
#include <excpt.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
Include dependency graph for nanomud-Main.c:

Go to the source code of this file.
Defines | |
| #define | COLOR_LTGRAY 0x00808080 |
Typedefs | |
| typedef termbuf | SBuf |
Functions | |
| EXCEPTION_DISPOSITION __cdecl | _except_handler (struct _EXCEPTION_RECORD *ExceptionRecord, void *EstablisherFrame, struct _CONTEXT *ContextRecord, void *DispatcherContext, char *file, int line) |
| void | check_output (void) |
| DWORD WINAPI | check_ping (void) |
| int | CloseWinsock (HWND hwnd, char *HostName) |
| LRESULT APIENTRY | EditProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| void | free_context (HDC context) |
| HDC | get_context () |
| void | get_scroll_pos () |
| void | give_term_debug (char *to_echo,...) |
| void | give_term_echo (char *to_echo,...) |
| void | give_term_error (char *to_echo,...) |
| void | GiveError (char *wrong, BOOL KillProcess) |
| int | HandleWinsockConnection (HWND hwnd, char *HostName) |
| void | InitializeClient (HINSTANCE hInst) |
| void | initwinsock (void) |
| void | richtextadd (HWND hwnd, char *add) |
| void | ScanWinsock (HWND hwnd) |
| LRESULT APIENTRY | WindowProcedure (HWND, UINT, WPARAM, LPARAM) |
| int WINAPI | WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) |
Variables | |
| sockaddr_in | address |
| unsigned long int | blarghish |
| UINT | BlinkT |
| int | BUF_LEN = 99999 |
| long int | bufcount |
| int | cols |
| bool | connected = FALSE |
| const char | echo_off_str [] = { IAC, WILL, TELOPT_ECHO, '\0' } |
| const char | echo_on_str [] = { IAC, WONT, TELOPT_ECHO, '\0' } |
| const char | go_ahead_str [] = { IAC, GA, '\0' } |
| char | Greet [] |
| HDC | hdcbuf |
| HBITMAP | hdcmap |
| HANDLE | hold |
| hostent * | host |
| PAINTSTRUCT | hps |
| HWND | hwnd |
| char | income_buff [8000] |
| HANDLE | m_hPingHandle = 0 |
| UINT | PingT |
| PAINTSTRUCT | ps |
| int | rows |
| DWORD | scratch |
| BOOL | selecting = FALSE |
| SBuf * | send_buff [100] |
| char | szClassName [] = "NanoMud v.1.00" |
| char | szTermName [] = "Terminal Area" |
| BOOL | tready = FALSE |
|
|
Definition at line 42 of file nanomud-Main.c. |
|
|
Definition at line 61 of file nanomud-Main.c. Referenced by handle_input(). |
|
||||||||||||||||||||||||||||
|
Definition at line 137 of file nanomud-Main.c. References LOG(). 00142 {
00143
00144 LOG("UNhandled exception occured. Killing client.");
00145
00146
00147 ContextRecord->Eax = (DWORD)&scratch;
00148 exit(1);
00149 }
|
Here is the call graph for this function:

|
|
Definition at line 984 of file nanomud-Main.c. References termbuf::buffer, send_buff, and sock. Referenced by handle_input(). 00985 {
00986 int runner,sent;
00987 int err;
00988
00989 if (send_buff[0]->buffer == '\0')
00990 return;
00991
00992 if (send_buff[0] == NULL)
00993 return;
00994
00995
00996 err = send(sock,send_buff[0]->buffer,strlen(send_buff[0]->buffer),0);
00997
00998 for (sent=0;sent<=100;sent++)
00999 if (send_buff[sent]->buffer == '\0')
01000 break;
01001
01002 for (runner=1;runner<=100;runner++)
01003 send_buff[runner-1]->buffer = send_buff[runner]->buffer; /* move everything down a notch */
01004
01005 return;
01006 }
|
|
|
Definition at line 294 of file nanomud-Main.c. References bufcount, CheckPing(), get_time(), session_data::host, MudMain, session_data::ping, sleep(), this_session, and total_alloc. Referenced by WinMain(). 00295 {
00296
00297 char buf[1228]="";
00298 extern unsigned long int total_alloc;
00299
00300 while (1)
00301 {
00302 sleep (1000);
00303 char temp[1000];
00304
00305
00306 CheckPing();
00307 sprintf(temp, "%u", (unsigned int)this_session->ping);
00308 sprintf(buf, "(%s) Host: %s Ping: %s%s Lines in buffer: %ld, Memory consumed: %lu kB",
00309 get_time(),
00310 this_session->host, this_session->ping > 1000 ? ">1" : temp,
00311 this_session->ping > 1000 ? "s" : "ms", bufcount, total_alloc/1024);
00312 SendMessage(MudMain, WM_SETTEXT, /*strlen(buf)-2*/0,(LPARAM)(LPCSTR) buf);
00313
00314
00315
00316
00317 }
00318 return 0;
00319 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1017 of file nanomud-Main.c. References connected, session_data::host, hwnd, session_data::port, realize_lines, this_session, and update_term(). Referenced by WindowProcedure(). 01018 {
01019 char tempp[1000];
01020 hwnd=0;HostName=0;
01021 sprintf(tempp, "TERM_ECHO: \e[1;32mDisconnected from %s:%d\e[0m.\n", this_session->host, this_session->port);
01022 realize_lines(tempp);
01023 update_term();
01024 connected = FALSE;
01025 return 0;
01026 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 1097 of file nanomud-Main.c. References handle_input(), hwnd, MudInput, and OldProc. Referenced by WindowProcedure(). 01098 {
01099 switch(msg)
01100 {
01101 case WM_MOUSEWHEEL:
01102 return DefWindowProc(hwnd,msg,wParam,lParam);
01103 break;
01104
01105
01106 case WM_KEYDOWN:
01107
01108 switch(wParam)
01109 {
01110
01111
01112 case 13:
01113 {
01114
01115
01116
01117
01118
01119 unsigned long int len = SendMessage(MudInput, WM_GETTEXTLENGTH,0,0);
01120
01121 char buff[len+10];
01122
01123 char addbuff[len+10];
01124 SendMessage(MudInput,WM_GETTEXT,len+4,(LPARAM)(LPCSTR)buff);
01125 CHARRANGE cr;
01126 cr.cpMin = 0;
01127 cr.cpMax = strlen(buff);
01128 SendMessage(MudInput, EM_EXSETSEL, 0, (LPARAM)&cr);
01129
01130 strcpy(addbuff,"\n");
01131 handle_input(buff);
01132
01133 }
01134 break;
01135
01136 default:
01137 return CallWindowProc(OldProc,hwnd,msg,wParam,lParam);
01138
01139 }
01140 default:
01141 return CallWindowProc(OldProc,hwnd,msg,wParam,lParam);
01142
01143 }
01144
01145
01146 }
|
Here is the call graph for this function:

|
|
Definition at line 1180 of file nanomud-Main.c. References hwnd. Referenced by do_update_paint(). 01181 {
01182 ReleaseDC(hwnd, context);
01183 }
|
|
|
Definition at line 1169 of file nanomud-Main.c. Referenced by term_test_2(). 01170 {
01171 HDC hdc;
01172 if (hwnd)
01173 {
01174 hdc = GetDC(MudMain);
01175 return hdc;
01176 }
01177 else
01178 return NULL;
01179 }
|
|
|
Definition at line 1010 of file nanomud-Main.c. References MudMain. Referenced by terminal_resize(), and update_term(). 01011 {
01012 SCROLLINFO sr;
01013 GetScrollInfo(MudMain, SB_VERT, &sr);
01014
01015 }
|
|
||||||||||||
|
Definition at line 1223 of file nanomud-Main.c. References realize_lines, and update_term(). Referenced by do_nasty(), do_term_test(), handle_input(), init_hash(), load_scripts(), and WinMain(). 01224 {
01225 char buf[20000];
01226
01227 va_list args;
01228 va_start (args, to_echo);
01229 vsprintf (buf, to_echo, args);
01230 va_end (args);
01231 to_echo = buf;
01232 char temp[strlen(to_echo) + 45];
01233 sprintf(temp, "\e[0mTERM_DEBUG: \e[0;36m%s\e[0m\n", to_echo);
01234
01235 realize_lines(temp);
01236 buf[0] = '\0';
01237 update_term();
01238 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1187 of file nanomud-Main.c. References realize_lines, tready, and update_term(). Referenced by handle_selection(), load_scripts(), parse_script(), and WinMain(). 01188 {
01189 char buf[20000];
01190
01191 if (tready == FALSE)
01192 return;
01193 va_list args;
01194 va_start (args, to_echo);
01195 vsprintf (buf, to_echo, args);
01196 va_end (args);
01197 to_echo = buf;
01198 char temp[strlen(to_echo) + 45];
01199 sprintf(temp, "\e[0mTERM_ECHO: \e[1;32m%s\e[0m\n", to_echo);
01200
01201 realize_lines(temp);
01202 buf[0] = '\0';
01203 update_term();
01204 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1206 of file nanomud-Main.c. References realize_lines, and update_term(). Referenced by do_if(), do_repeat(), handle_set_options(), HandleWinsockConnection(), load_settings(), and save_settings(). 01207 {
01208 char buf[20000];
01209
01210 va_list args;
01211 va_start (args, to_echo);
01212 vsprintf (buf, to_echo, args);
01213 va_end (args);
01214 to_echo = buf;
01215 char temp[strlen(to_echo) + 45];
01216 sprintf(temp, "\e[0mTERM_ERROR: \e[1;31m%s\e[0m\n", to_echo);
01217
01218 realize_lines(temp);
01219 buf[0] = '\0';
01220 update_term();
01221 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1151 of file nanomud-Main.c. References MudMain. 01152 {
01153 if (wrong == NULL)
01154 {
01155 MessageBox(MudMain, "An unknown error has occured, please restart NanoMud and try again.", "NanoMud Error", MB_ICONSTOP | MB_OK);
01156 if (KillProcess)
01157 exit(0);
01158 else
01159 return;
01160 }
01161
01162 MessageBox(MudMain, wrong, "NanoMud Error", MB_ICONSTOP | MB_OK);
01163 if (KillProcess)
01164 exit(0);
01165 else
01166 return;
01167 }
|
|
||||||||||||
|
Definition at line 1028 of file nanomud-Main.c. References address, session_data::connected, connected, session_data::desc, FALSE, give_term_error(), GiveError(), host, session_data::host, hwnd, MudMain, session_data::port, session_data::rawSocket, realize_lines, session_data::saDest, sock, this_session, update_term(), and WM_SOCKET. Referenced by WindowProcedure(). 01029 {
01030
01031
01032
01033
01034
01035 LPHOSTENT lpHost;
01036
01037
01038 address.sin_family=AF_INET;
01039 address.sin_port = htons(this_session->port);
01040 if ( (sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET )
01041 exit(0);
01042 if ( (host=gethostbyname(HostName)) == NULL )
01043 {
01044 give_term_error("Unable to find mud! %s", HostName);
01045 return 0;
01046
01047 }
01048
01049 address.sin_addr.s_addr=*((unsigned long *) host->h_addr);
01050 if ( (this_session->desc= connect(sock,(struct sockaddr *) &address, sizeof(address))) != 0)
01051 {
01052 MessageBox(hwnd, "Unable to connect.", "Error", MB_OK);
01053 return 0;
01054 }
01055 this_session->rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
01056 if (this_session->rawSocket == SOCKET_ERROR)
01057 {
01058 GiveError("Unable to create raw socket in CheckPing().",FALSE);
01059 return 0;
01060 }
01061
01062 lpHost = gethostbyname(this_session->host);
01063 if (lpHost == NULL)
01064 {
01065 return 0;
01066 }
01067 this_session->saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr));
01068 this_session->saDest.sin_family = AF_INET;
01069 this_session->saDest.sin_port = 0;
01070 //PingT = SetTimer(MudMain,1500 , 10000, NULL);
01071 //WindowProcedure (MudMain, WM_TIMER,0,0); /* Cheap hack for lazyness */
01072 this_session->connected = TRUE;
01073 char tempp[1000];
01074 sprintf(tempp, "TERM_ECHO: \e[1;32mConnected to %s:%d\e[0m\n", this_session->host, this_session->port);
01075 realize_lines(tempp);
01076 update_term();
01077 char tt[100]="";
01078 sprintf(tt,"%s[CIP;68.62.139.144\n", "\e");
01079 int err;
01080 err =0;
01081 err = send(sock,tt,strlen(tt),0);
01082 WSAAsyncSelect(sock,MudMain,WM_SOCKET, FD_READ|FD_CLOSE);
01083 connected = TRUE;
01084
01085
01086
01087 return 0;
01088 }
|
Here is the call graph for this function:

|
|
Definition at line 321 of file nanomud-Main.c. References malloc, tbuf, and this_session. Referenced by WinMain(). 00322 {
00323 WNDCLASS wc;
00324
00325 wc.cbClsExtra = 0;
00326 wc.cbWndExtra = 0;
00327 wc.hbrBackground =(HBRUSH) 7;
00328 wc.lpfnWndProc = (WNDPROC) WindowProcedure;
00329 wc.lpszClassName = szClassName;
00330 wc.lpszMenuName = NULL;
00331 wc.hInstance = hInst;
00332 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00333 wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00334 wc.style = CS_DBLCLKS;
00335
00336 RegisterClass(&wc);
00337 this_session = malloc(sizeof(*this_session));
00338 tbuf = malloc(sizeof(*tbuf));
00339 wc.cbClsExtra = 0;
00340 wc.cbWndExtra = 0;
00341 wc.hbrBackground =(HBRUSH) 1;
00342 wc.lpszClassName = "About";
00343 wc.lpfnWndProc = (WNDPROC) AboutProcedure;
00344 wc.lpszMenuName = NULL;
00345 wc.hInstance = hInst;
00346 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00347 wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00348 wc.style = CS_DBLCLKS;
00349
00350 RegisterClass(&wc);
00351
00352 wc.cbClsExtra = 0;
00353 wc.cbWndExtra = 0;
00354 wc.hbrBackground =(HBRUSH) 1;
00355 wc.lpszClassName = "Credit";
00356 wc.lpfnWndProc = (WNDPROC) CreditProcedure;
00357 wc.lpszMenuName = NULL;
00358 wc.hInstance = hInst;
00359 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00360 wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00361 wc.style = CS_DBLCLKS;
00362
00363 RegisterClass(&wc);
00364
00365 wc.cbClsExtra = 0;
00366 wc.cbWndExtra = 0;
00367 wc.hbrBackground =(HBRUSH) 1;
00368 wc.lpszClassName = "Settings";
00369 wc.lpfnWndProc = (WNDPROC) SettingsProcedure;
00370 wc.lpszMenuName = NULL;
00371 wc.hInstance = hInst;
00372 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00373 wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00374 wc.style = CS_DBLCLKS;
00375
00376 RegisterClass(&wc);
00377
00378
00379
00380
00381 }
|
|
|
Definition at line 383 of file nanomud-Main.c. References GiveError(), and wsaData. Referenced by WinMain(). 00384 {
00385
00386 WORD wVersionRequested;
00387 WSADATA wsaData;
00388 int err;
00389
00390 wVersionRequested = MAKEWORD( 1, 1 );
00391 err = WSAStartup( wVersionRequested, &wsaData );
00392
00393
00394 if ( err != 0 )
00395 GiveError("Unable to find winsock.",1);
00396
00397
00398 return;
00399 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1089 of file nanomud-Main.c. References hwnd. 01090 {
01091 int len;
01092 len = SendMessage(hwnd,WM_GETTEXTLENGTH,0,0);
01093 SendMessage(hwnd,EM_SETSEL,len,len);
01094 SendMessage(hwnd,EM_REPLACESEL,strlen(add),(LPARAM)(LPCSTR)add);
01095 return;
01096 }
|
|
|
|
|
||||||||||||||||||||
|
Definition at line 401 of file nanomud-Main.c. References BLACK, blink_term(), blinked, BlinkT, bufcount, termbuffer::buffer, CloseWinsock(), cols, CreateAboutBox(), CreateCreditBox(), CreateSettings(), seltext::cstart, seltext::cstop, do_nasty(), do_update_paint(), echo_off, echo_off_str, echo_on_str, EditProc(), export_to_html(), FALSE, fetch_line(), FlushBuffer(), FormatText(), free, free_scripts(), FreeTerm(), g_hInst, get_hash(), get_x(), GiveError(), go_ahead_str, HandleWinsockConnection(), hdc, termbuf::hdc, session_data::host, termbuf::hwnd, hwnd, ID_EDIT_COPY, ID_EDIT_FIND, ID_EDIT_FIND_NEXT, ID_EDIT_PASTE, ID_EDIT_SALL, ID_EDIT_SEND, ID_FILE_CLOSE, ID_FILE_DISCONNECT, ID_FILE_EXIT, ID_FILE_EXPORT_ANSI, ID_FILE_EXPORT_HTML, ID_FILE_EXPORT_TEXT, ID_FILE_IMPORT_ANSI, ID_FILE_NEW, ID_FILE_OPEN, ID_HELP_ABOUT, ID_HELP_CREDITS, ID_HELP_HELP, ID_MUDINPUT, ID_SETTINGS_CONFIGURE, ID_SETTINGS_OPTIONS, ID_SETTINGS_STATUS, ID_TIMER_BLINK, interp_mouse(), IS_IN_DEBUGGING_MODE, seltext::lstart, seltext::lstop, MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT, Mud_client_Version, MudAbout, MudCredit, MudInput, MudMain, mudrect, MudSettings, OldProc, ParseLines(), PingT, pos, session_data::proc, return_usage(), rows, save_scripts(), scroll_term(), seltext::selected, selecting, selection, send_buff, sock, tbuf, TERMBUF, Terminal, terminal_resize(), session_data::termlist, this_session, TRUE, TRUE_BLACK, update_term(), walk_heap(), WM_SOCKET, poss::x, and poss::y. 00402 {
00403
00404
00405
00406 switch (message)
00407 {
00408
00409 case WM_CREATE:
00410 {
00411 HMENU hMenu, hSubMenu;
00412 extern RECT mudrect;
00413 RECT term;
00414
00415
00416
00417
00418 hMenu = CreateMenu();
00419 hSubMenu = CreatePopupMenu();
00420 AppendMenu(hSubMenu, MF_STRING, ID_FILE_NEW, "&New");
00421 AppendMenu(hSubMenu, MF_STRING |MF_POPUP, ID_FILE_CLOSE, "&Close");
00422 AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, "&Open");
00423 AppendMenu(hSubMenu, MF_STRING, ID_FILE_DISCONNECT, "&Disconnect");
00424 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00425 AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXPORT_HTML, "&Export HTML log");
00426 AppendMenu(hSubMenu, MF_STRING |MF_POPUP|MF_GRAYED, ID_FILE_EXPORT_TEXT, "E&xport TEXT log");
00427 AppendMenu(hSubMenu, MF_STRING |MF_POPUP|MF_GRAYED, ID_FILE_EXPORT_ANSI, "Ex&port ANSI log");
00428 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00429 AppendMenu(hSubMenu, MF_STRING , ID_FILE_IMPORT_ANSI, "I&mport ANSI/TEXT log");
00430 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00431 AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
00432 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
00433 SetMenu(hwnd, hMenu);
00434 hSubMenu = CreatePopupMenu();
00435 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_FIND, "&Find");
00436 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_FIND_NEXT, "Find &Next");
00437 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_PASTE, "&Paste");
00438 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_COPY, "&Copy");
00439 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_SEND, "&Send File to MUD");
00440 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_SALL, "S&elect All");
00441 AppendMenu(hMenu, MF_STRING|MF_POPUP, (UINT)hSubMenu, "&Edit");
00442 SetMenu(hwnd, hMenu);
00443 hSubMenu = CreatePopupMenu();
00444 AppendMenu(hSubMenu, MF_STRING, ID_SETTINGS_CONFIGURE, "&Configure");
00445 AppendMenu(hSubMenu, MF_STRING, ID_SETTINGS_STATUS, "C&lient Status");
00446 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00447 AppendMenu(hSubMenu, MF_STRING, ID_SETTINGS_OPTIONS, "&Options");
00448 AppendMenu(hMenu, MF_STRING |MF_POPUP, (UINT)hSubMenu, "&Settings");
00449 SetMenu(hwnd, hMenu);
00450 hSubMenu = CreatePopupMenu();
00451 AppendMenu(hSubMenu, MF_STRING, ID_HELP_HELP, "&Help");
00452 AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "&About");
00453 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00454 AppendMenu(hSubMenu, MF_STRING, ID_HELP_CREDITS, "&Credits");
00455 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");
00456 SetMenu(hwnd, hMenu);
00457 tbuf->hdc = GetDC(MudMain);
00458 GetClientRect(hwnd, &mudrect);
00459 GetClientRect(Terminal, &term);
00460 MudInput = CreateWindowEx(WS_EX_CLIENTEDGE, "RICHEDIT","",WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,mudrect.left,mudrect.bottom-20, mudrect.right, 20,hwnd, (HMENU)ID_MUDINPUT,g_hInst,0);
00461 SendMessage(MudInput, EM_SETEVENTMASK, 0,0);
00462
00463 OldProc = (WNDPROC) SetWindowLong(MudInput,GWL_WNDPROC,(LONG)EditProc);
00464 //MudStatus = CreateWindowEx(WS_EX_CLIENTEDGE, "STATIC", "", WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,mudrect.left,mudrect.bottom-60, mudrect.right, 20,hwnd, (HMENU)ID_STATUS,g_hInst,0);
00465 //SendMessage(MudStatus, EM_SETEVENTMASK,0,0);
00466 tbuf->hwnd = hwnd;
00467 //ShowWindow(MudInput, SW_SHOW);
00468
00469 }
00470 break;
00471
00472 case WM_SIZE:
00473 {
00474 RECT mudwin;
00475
00476 GetClientRect(MudMain, &mudwin);
00477 MoveWindow(MudInput, mudwin.left, mudwin.bottom-20, mudwin.right, 20, TRUE);
00478 terminal_resize ();
00479
00480 break;
00481
00482 }
00483
00484 case WM_COMMAND:
00485 switch(LOWORD(wParam))
00486 {
00487
00488 case ID_EDIT_FIND:
00489 break;
00490
00491 case ID_EDIT_FIND_NEXT:
00492 break;
00493
00494 case ID_EDIT_PASTE:
00495 break;
00496
00497 case ID_EDIT_COPY:
00498 FreeTerm();
00499 break;
00500
00501 case ID_EDIT_SEND:
00502 break;
00503
00504 case ID_EDIT_SALL:
00505 break;
00506
00507
00508 case ID_FILE_EXIT:
00509 {
00510 char buf[100];
00511 if (IS_IN_DEBUGGING_MODE == 1)
00512 sprintf(buf, "Thank you for using NanoMud v.%s.",Mud_client_Version);
00513 else
00514 sprintf(buf, "Thank you for using NanoMud v.%s.",Mud_client_Version);
00515
00516 MessageBox(hwnd, buf, "NanoMud", MB_OK);
00517 FreeTerm();
00518 return_usage();
00519 int runner;
00520 for (runner=0;runner<=100;runner++)
00521 {
00522 free(send_buff[runner]);
00523
00524 }
00525 free (this_session->termlist);
00526 free (this_session);
00527 free (tbuf);
00528 free_scripts();
00529
00530 save_scripts();
00531 walk_heap();
00532 PostQuitMessage (0);
00533 break;
00534 }
00535 case ID_FILE_OPEN:
00536 HandleWinsockConnection(hwnd, this_session->host);
00537 break;
00538
00539 case ID_FILE_DISCONNECT:
00540 CloseWinsock(hwnd, this_session->host);
00541 break;
00542
00543 case ID_FILE_EXPORT_HTML:
00544 export_to_html();
00545 break;
00546
00547 case ID_FILE_EXPORT_TEXT:
00548 break;
00549
00550 case ID_FILE_EXPORT_ANSI:
00551 break;
00552
00553 case ID_FILE_IMPORT_ANSI:
00554 // do_term_test();
00555 do_nasty();
00556 //update_term();
00557 break;
00558
00559 case ID_FILE_CLOSE:
00560 {
00561 this_session->proc = &give_term_echo;
00562 this_session->proc("Testing moved to import.");
00563 break;
00564 }
00565
00566 case ID_FILE_NEW:
00567 break;
00568
00569 case ID_SETTINGS_CONFIGURE:
00570 CreateSettings();
00571 break;
00572
00573 case ID_SETTINGS_STATUS:
00574 MessageBox(hwnd, "Client Status...not working?", "NanoMud", MB_OK);
00575 break;
00576
00577 case ID_SETTINGS_OPTIONS:
00578 MessageBox(hwnd, "Options: StubFunction", "NanoMud", MB_OK);
00579 break;
00580
00581 case ID_HELP_HELP:
00582 {
00583 unsigned int i;
00584 TERMBUF *t;
00585 for (i=0;i<=bufcount;i++)
00586 {
00587 t = fetch_line(i);
00588 if (t)
00589 if (t->buffer)
00590 {
00591 free(t->buffer);
00592 t->buffer = NULL;
00593 }
00594 }
00595 }
00596 // do_url("http://www.nanobit.net");
00597 break;
00598
00599 case ID_HELP_ABOUT:
00600 CreateAboutBox();
00601 break;
00602
00603 case ID_HELP_CREDITS:
00604 CreateCreditBox();
00605 break;
00606
00607 }
00608 case WM_SETFOCUS:
00609
00610
00611 if (IsWindow(MudAbout))
00612 break;
00613 else if (IsWindow(MudCredit))
00614 break;
00615 else if (IsWindow(MudSettings))
00616 break;
00617 else
00618 {
00619 // InvalidateRect(MudMain, NULL, TRUE);
00620
00621 SetFocus(MudInput);
00622 }
00623
00624 break;
00625 case WM_LBUTTONDOWN:
00626 {
00627
00628
00629 int x,y=0;
00630 y = LOWORD(lParam);
00631 x = HIWORD(lParam);
00632 selecting = TRUE;
00633 interp_mouse(x/13,(y-8)/8,MOUSE_LEFT);
00634 x = x / 13;
00635 y = (y -8) / 8;
00636
00637
00638
00639 selection->lstart = get_x(x);
00640 selection->cstart = y;
00641 selection->lstop = get_x(x);
00642 selection->cstop = y;
00643 selection->selected = FALSE;
00644 // handle_selection();
00645
00646 update_term();
00647
00648 return DefWindowProc(hwnd, message, wParam, lParam);
00649
00650 }
00651 break;
00652
00653 case WM_RBUTTONDOWN:
00654 {
00655 int x,y=0;
00656 y = LOWORD(lParam);
00657 x = HIWORD(lParam);
00658 interp_mouse(x/13,(y-8)/8,MOUSE_RIGHT);
00659 update_term();
00660 return DefWindowProc(hwnd, message, wParam, lParam);
00661 }
00662 break;
00663 case WM_MBUTTONDOWN:
00664 {
00665 int x,y=0;
00666 y = LOWORD(lParam);
00667 x = HIWORD(lParam);
00668 interp_mouse(x/13,(y-8)/8,MOUSE_MIDDLE);
00669 return DefWindowProc(hwnd, message, wParam, lParam);
00670 }
00671 break;
00672
00673 case WM_MOUSEMOVE:
00674
00675 {
00676
00677
00678 if ((wParam & (MK_LBUTTON | !MK_SHIFT)))
00679 {
00680 selection->selected = TRUE;
00681 int x,y=0;
00682 y=LOWORD(lParam);
00683 x=HIWORD(lParam);
00684 x = x / 13;
00685 y = (y - 8) / 8;
00686 selection->lstop = get_x(x);
00687 selection->cstop = y;
00688 RECT r;
00689 r.top = x ;
00690 r.bottom = x * 13+1;
00691 r.right =100;
00692 r.left = 0;
00693
00694 update_term();
00695
00696
00697
00698
00699 }
00700 else
00701 {
00702 int x,y=0;
00703 char buf[100];
00704 y=LOWORD(lParam);
00705 x=HIWORD(lParam);
00706 extern poss pos;
00707 pos.x = x/13;
00708 pos.y = y/8;
00709 sprintf(buf, "row: %d(%d), col: %d(%d)", (x)/13,x,(y)/8,y);
00710 tbuf->y_end = rows * 13-15;
00711 tbuf->x_end = cols * 4 - 50;
00712
00713 FlushBuffer(buf, BLACK,TRUE_BLACK);
00714 // update_term();
00715
00716 }
00717
00718
00719
00720 break;
00721 }
00722 break;
00723
00724 case WM_LBUTTONUP:
00725 {
00726 int x,y=0;
00727 y=LOWORD(lParam);
00728 x=HIWORD(lParam);
00729
00730 x = x / 13;
00731 y = (y - 8) / 8;
00732
00733 selection->cstop = y;
00734 }
00735
00736 break;
00737
00738
00739
00740
00741 case WM_SOCKET:
00742
00743 switch(LOWORD(lParam))
00744 {
00745 case FD_READ:
00746 {
00747
00748
00749 char readbuff[22460]="";
00750 char Buf[22460]="";
00751
00752
00753 char readbuffer[22460]="";
00754 char *ansi;
00755 int err=10;
00756 readbuff[0]='\0';
00757 err = 1;
00758 err = recv(sock, readbuff, sizeof(readbuff), 0);
00759
00760
00761
00762
00763
00764 if (err != 0)
00765 {
00766
00767
00768 int buflen=strlen(readbuff);
00769 Buf[0] = '\0';
00770 ansi = Buf;
00771 if (strstr(readbuff, echo_off_str))
00772 {
00773 strcpy(readbuffer,readbuff);
00774 echo_off = TRUE;
00775
00776 readbuffer[strlen(readbuff)] = readbuff[buflen - strlen(echo_off_str)];
00777 readbuffer[strlen(readbuff)+1] = '\0';
00778 strcpy(readbuff, readbuffer);
00779 }
00780 if (strstr(readbuff, echo_on_str))
00781 {
00782 strcpy(readbuffer,readbuff);
00783 echo_off = FALSE;
00784 SendMessage(MudInput, EM_SETEVENTMASK, 0,0);
00785 readbuffer[strlen(readbuff)]=readbuff[buflen-strlen(echo_on_str)];
00786 readbuffer[strlen(readbuff)+1]='\0';
00787 strcpy(readbuff, readbuffer);
00788 }
00789 if (strstr(readbuff, go_ahead_str))
00790 {
00791 strcpy(readbuffer,readbuff);
00792 readbuffer[strlen(readbuff)]=readbuff[buflen-strlen(go_ahead_str)];
00793 readbuffer[strlen(readbuff)+1]='\0';
00794 strcpy(readbuff,readbuffer);
00795 }
00796 get_hash(readbuff);
00797 ParseLines(readbuff);
00798
00799 readbuff[0] = '\0';
00800 readbuffer[0]='\0';
00801
00802 }
00803 else
00804 {
00805 GiveError("Unknown Error with Winsock recv();",1);
00806 return 0;
00807 }
00808
00809 }
00810 break;
00811
00812 case FD_CLOSE:
00813 {
00814 GiveError("Connection Closed by remote host.\nConntion Lost! Possible reasons:\n1)Your connection dropped\n2)Remote server went down\n3)You just suck.\n4) (added for rob) or you could have typed quit. :)", FALSE);
00815 char buf[100];
00816 if (IS_IN_DEBUGGING_MODE == 1)
00817 sprintf(buf, "Thank you for using NanoMud v. %s.","0");
00818 else
00819 sprintf(buf, "Thank you for using NanoMud v. %s.","0");
00820 MessageBox(hwnd, buf, "NanoMud", MB_OK);
00821 save_scripts();
00822 FreeTerm();
00823 return_usage();
00824 int runner;
00825 for (runner=0;runner<=100;runner++)
00826 {
00827 free(send_buff[runner]);
00828
00829 }
00830 free (this_session->termlist);
00831 free (this_session);
00832 free (tbuf);
00833 free_scripts();
00834
00835
00836 KillTimer(MudMain, PingT);
00837 KillTimer(MudMain, BlinkT);
00838 WSACleanup();
00839 return_usage();
00840 walk_heap();
00841 PostQuitMessage (0);
00842 break;
00843
00844 break;
00845 }
00846 default:
00847 return DefWindowProc (hwnd, message, wParam, lParam);
00848
00849
00850 }
00851 break;
00852
00853 case WM_DESTROY:
00854 {
00855
00856 char buf[100];
00857 if (IS_IN_DEBUGGING_MODE == 1)
00858 sprintf(buf, "Thank you for using NanoMud v. %s.","0");
00859 else
00860 sprintf(buf, "Thank you for using NanoMud v. %s.","0");
00861 MessageBox(hwnd, buf, "NanoMud", MB_OK);
00862 save_scripts();
00863 FreeTerm();
00864 return_usage();
00865 int runner;
00866 for (runner=0;runner<=100;runner++)
00867 {
00868 free(send_buff[runner]);
00869
00870 }
00871 free (this_session->termlist);
00872 free (this_session);
00873 free (tbuf);
00874 free_scripts();
00875
00876
00877 KillTimer(MudMain, PingT);
00878 KillTimer(MudMain, BlinkT);
00879 WSACleanup();
00880 return_usage();
00881 walk_heap();
00882 PostQuitMessage (0);
00883 break;
00884 }
00885
00886 case WM_TIMER:
00887 {
00888 switch(LOWORD(wParam))
00889 {
00890 case ID_TIMER_BLINK:
00891 {
00892
00893 if (blinked == TRUE)
00894 blinked = FALSE;
00895 else
00896 blinked = TRUE;
00897 blink_term();
00898 break;
00899 }
00900
00901 }
00902 break;
00903 }
00904
00905
00906
00907
00908 case WM_PAINT:
00909 {
00910
00911 PAINTSTRUCT p;
00912 HDC hdc = BeginPaint(hwnd,&p);
00913
00914 do_update_paint(hdc, (p.rcPaint.left-8)/8, (p.rcPaint.top-13)/13,(p.rcPaint.right-8-1)/8,
00915 (p.rcPaint.bottom-13-1)/13);
00916 EndPaint(hwnd,&p);
00917 break;
00918
00919 }
00920
00921
00922 case WM_VSCROLL:
00923 switch(LOWORD(wParam))
00924 {
00925
00926 case SB_TOP:
00927 scroll_term(+1,0);
00928 break;
00929 case SB_THUMBPOSITION:
00930 case SB_THUMBTRACK:
00931 scroll_term(1, (LONG)HIWORD(wParam));
00932 break;
00933 case SB_PAGEUP:
00934 scroll_term(0, -(bufcount / 10));
00935 break;
00936 case SB_PAGEDOWN:
00937 scroll_term(0, bufcount / 10);
00938 break;
00939 case SB_BOTTOM:
00940 scroll_term(-1,0);
00941 break;
00942 case SB_LINEDOWN:
00943 scroll_term(0,+10);
00944 break;
00945 case SB_LINEUP:
00946 scroll_term(0,-10);
00947 break;
00948 default:
00949 return DefWindowProc(hwnd, message,wParam,lParam);
00950
00951 }
00952 break;
00953
00954 case WM_MOUSEWHEEL:
00955 {
00956 int pos=0;
00957 int way=0;
00958 pos += (short)HIWORD(wParam);
00959
00960 if (pos < 0)
00961 way = 0;
00962 else if (pos > 0)
00963 way = 1;
00964 scroll_term(0, way == 0 ? +50 : -50);
00965
00966 break;
00967 }
00968
00969
00970
00971
00972
00973
00974 default:
00975 FormatText(MudInput);
00976 return DefWindowProc (hwnd, message, wParam, lParam);
00977 break;
00978
00979 }
00980
00981 return 0;
00982 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 153 of file nanomud-Main.c. References BlinkT, termbuf::buffer, check_ping(), session_data::colour, FormatText(), g_hInst, get_time(), give_term_debug(), give_term_echo(), GiveError(), Greet, termbuf::hdc, hdc, hf, session_data::host, hwnd, ID_TIMER_BLINK, init_scripts(), InitializeClient(), initwinsock(), load_scripts(), load_settings(), malloc, session_data::max_buffer, MudInput, MudMain, session_data::name, ParseLines(), session_data::port, save_settings(), send_buff, sock, szClassName, tbuf, TERMBUF, terminal_initialize(), session_data::termlist, this_session, tready, TRUE, update_term(), and WM_SOCKET. 00158 {
00159
00160 MSG messages;
00161 extern HFONT hf;
00162 // extern RECT mudrect;
00163 hPrevInstance=0;
00164 lpszArgument=0;
00165 nFunsterStil=0;
00166
00167
00168 // DWORD handler = (DWORD)_except_handler;
00169 // SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)handler);
00170
00171
00172
00173 LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL;
00174 DWORD stackSize = 0;
00175 int theArg;
00176 DWORD dwCreationFlags = 0;
00177 DWORD targetThreadID;
00178
00179 _beginthreadex ((void *) lpThreadAttributes,(unsigned) stackSize,(unsigned (_stdcall *) (void *))check_ping,(void *) &theArg,(unsigned) dwCreationFlags, (unsigned *) &targetThreadID);
00180
00181
00182
00183
00184
00185
00186
00187 LoadLibrary("RichEd32.Dll");
00188
00189 InitializeClient(hThisInstance);
00190 g_hInst = hThisInstance;
00191 MudMain = CreateWindow(szClassName,"NanoMud Main Window -- Nanobit Software (C) 2004",
00192 WS_SYSMENU|WS_VSCROLL|WS_MINIMIZEBOX|WS_MAXIMIZE|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_SIZEBOX,
00193 0,0,800,600,0,0,hThisInstance,0);
00194
00195
00196 hwnd = MudMain;
00197 initwinsock();
00198
00199 WSAAsyncSelect(sock,MudMain,WM_SOCKET, FD_CLOSE|FD_READ);
00200 this_session->max_buffer =1000000;
00201 this_session->name = "MUD";
00202 this_session->host = "s001.ns-inf.net";
00203 this_session->port = 4000;
00204
00205
00206 this_session->colour = TRUE;
00207
00208
00209 this_session->termlist = (TERMBUF **)malloc(this_session->max_buffer * sizeof(*this_session->termlist));
00210 terminal_initialize();
00211
00212 tbuf->x_start = 0;
00213 tbuf->x_end = 0;
00214 tbuf->y_start = 0;
00215 tbuf->y_end = 0;
00216
00217
00218
00219
00220 int runner;
00221 for (runner=0;runner<=100;runner++)
00222 {
00223 send_buff[runner] = malloc(sizeof(char));
00224 send_buff[runner]->buffer = '\0';
00225 }
00226 if (tbuf == NULL)
00227 GiveError("Tbuf->buffer failed to initialize", TRUE);
00228
00229 HDC hdc;
00230 hdc = GetDC(MudMain);
00231
00232 tbuf->hdc = hdc;
00233 UpdateWindow(MudMain);
00234 hf = CreateFont(13, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, DEFAULT_QUALITY, 0, "Courier");
00235 SetBkColor(hdc,RGB(0,0,0));
00236 SetTextColor(hdc, RGB(0,128,0));
00237
00238 //GetClientRect(Terminal, &mudrect);
00239
00240 FormatText(MudInput);
00241
00242 give_term_echo("Welcome to nanomud!\n");
00243 init_scripts();
00244 give_term_debug("Loading scripts.");
00245 load_scripts();
00246 // init_hash(65000);
00247 give_term_debug("Loading settings.");
00248 load_settings();
00249 save_settings();
00250 give_term_debug("Sizeof termbuf: %lu", sizeof(TERMBUF));
00251 give_term_debug("ANSI_CLEAR \e[0mtest");
00252 give_term_debug("ANSI_RED \e[0;31mtest");
00253 give_term_debug("ANSI_GREEN \e[0;32mtest");
00254 give_term_debug("ANSI_YELLOW \e[0;33mtest");
00255 give_term_debug("ANSI_BLUE \e[0;34mtest");
00256 give_term_debug("ANSI_MAGENTA \e[0;35mtest");
00257 give_term_debug("ANSI_CYAN \e[0;36mtest");
00258 give_term_debug("ANSI_WHITE \e[0;37mtest");
00259 give_term_debug("ANSI_C_GREY \e[1;30mtest");
00260 give_term_debug("ANSI_C_RED \e[1;31mtest");
00261 give_term_debug("ANSI_C_GREEN \e[1;32mtest");
00262 |