Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

nanomud-Main.c File Reference

#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 dependency graph for nanomud-Main.c:

Include dependency graph

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 (LPVOID param)
int CloseWinsock (HWND hwnd, char *HostName)
void create_hdc_buf (void)
void do_bit ()
LRESULT APIENTRY EditProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
void free_context (HDC context)
void free_hdc_buf (void)
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 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
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' }
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
SBufsend_buff [100]
char szClassName [] = "NanoMud v.1.00"
char szTermName [] = "Terminal Area"
BOOL tready = FALSE


Define Documentation

#define COLOR_LTGRAY   0x00808080
 

Definition at line 39 of file nanomud-Main.c.


Typedef Documentation

typedef struct termbuf SBuf
 

Definition at line 57 of file nanomud-Main.c.

Referenced by check_output(), and handle_input().


Function Documentation

EXCEPTION_DISPOSITION __cdecl _except_handler struct _EXCEPTION_RECORD *  ExceptionRecord,
void *  EstablisherFrame,
struct _CONTEXT *  ContextRecord,
void *  DispatcherContext,
char *  file,
int  line
 

Definition at line 88 of file nanomud-Main.c.

References GiveError(), and TRUE.

00093 {
00094     unsigned i;
00095     char temp[1000];
00096 
00097     sprintf(temp, "Fatal Exception: Line: %d, File: %s", line, file);
00098     GiveError( temp,TRUE);
00099     ContextRecord->Eax = (DWORD)&scratch;
00100     return ExceptionContinueExecution;
00101 }

Here is the call graph for this function:

void check_output void   ) 
 

Definition at line 767 of file nanomud-Main.c.

References termbuf::buffer, free, malloc, SBuf, send_buff, and sock.

Referenced by handle_input().

00768 {
00769     int runner,sent;
00770     int err;
00771 
00772     if (send_buff[0]->buffer == '\0')
00773         return;
00774 
00775     SBuf * temp_buff[100];
00776     if (send_buff[0] == NULL)
00777         return;
00778     
00779            
00780     
00781 
00782     for (runner=0;runner<=100;runner++)
00783     {
00784         temp_buff[runner] = malloc(sizeof(char));
00785         temp_buff[runner]->buffer = '\0';
00786     }
00787     
00788     
00789     err = send(sock,send_buff[0]->buffer,strlen(send_buff[0]->buffer),0);
00790         
00791     for (sent=0;sent<=100;sent++)
00792         if (send_buff[sent]->buffer == '\0')
00793             break;
00794             
00795     for (runner=1;runner<=100;runner++)
00796         temp_buff[runner-1]->buffer = send_buff[runner]->buffer; /* move everything down a notch */
00797     
00798     for (runner=0;runner<=100;runner++)
00799         send_buff[runner]->buffer = temp_buff[runner]->buffer;
00800     for (runner=0;runner<=100;runner++)
00801         free(temp_buff[runner]);
00802         
00803     return;
00804 }

DWORD WINAPI check_ping LPVOID  param  ) 
 

Definition at line 217 of file nanomud-Main.c.

References bufcount, CheckPing(), session_data::host, MudMain, session_data::ping, and this_session.

Referenced by WinMain().

00218 {
00219   char buf[128]="";
00220   
00221   while (1)
00222   {
00223     sleep (5000);
00224     
00225     CheckPing();
00226     sprintf(buf, "Host: %s Ping: %ldms Lines in buffer: %d",
00227     this_session->host, this_session->ping, bufcount);
00228     SendMessage(MudMain, WM_SETTEXT, /*strlen(buf)-2*/0,(LPARAM)(LPCSTR) buf);
00229   }
00230 }

Here is the call graph for this function:

int CloseWinsock HWND  hwnd,
char *  HostName
 

Definition at line 815 of file nanomud-Main.c.

References connected, session_data::host, session_data::port, realize_lines(), this_session, and update_term().

Referenced by WindowProcedure().

00816 {
00817     char tempp[1000];
00818     sprintf(tempp, "TERM_ECHO: \e[1;32mDisconnected from %s:%d\e[0m.\n", this_session->host, this_session->port);
00819     realize_lines(tempp);
00820     update_term();
00821     connected = FALSE;
00822 }                

Here is the call graph for this function:

void create_hdc_buf void   ) 
 

Definition at line 975 of file nanomud-Main.c.

References hdc, hdcbuf, hdcmap, hold, hps, and MudMain.

Referenced by do_bit(), and WinMain().

00976 {
00977     HDC hdc;
00978     RECT rmud;
00979     
00980     GetClientRect(MudMain, &rmud);
00981      
00982     hdc = BeginPaint (MudMain, &hps);
00983     hdcbuf = CreateCompatibleDC(hdc);
00984     hdcmap = CreateCompatibleBitmap (hdc, rmud.right, rmud.bottom);
00985     hold = SelectObject(hdcbuf, hdcmap);
00986     EndPaint(MudMain, &hps);
00987     
00988 }

void do_bit  ) 
 

Definition at line 997 of file nanomud-Main.c.

References create_hdc_buf(), free_hdc_buf(), termbuf::hdc, hdcbuf, MudMain, and tbuf.

00998 {
00999     RECT r;
01000     GetClientRect(MudMain, &r);
01001     BitBlt(tbuf->hdc, 0, 0, r.right, r.bottom,hdcbuf , 0, 0, SRCCOPY);        
01002     free_hdc_buf();
01003     create_hdc_buf();
01004 }

Here is the call graph for this function:

LRESULT APIENTRY EditProc HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam
 

Definition at line 887 of file nanomud-Main.c.

References handle_input(), hwnd, MudInput, and OldProc.

Referenced by WindowProcedure().

00888 {
00889   switch(msg)
00890     {
00891         case WM_MOUSEWHEEL:
00892             return DefWindowProc(hwnd,msg,wParam,lParam);
00893             break;
00894 
00895 
00896     case WM_KEYDOWN:
00897         
00898     switch(wParam)
00899     {
00900         
00901 
00902         case 13:
00903         {
00904 
00905           int err;
00906           extern HFONT hf;
00907           extern RECT mudrect;
00908           
00909           unsigned long int len = SendMessage(MudInput, WM_GETTEXTLENGTH,0,0);
00910           
00911           char buff[len+10];
00912           char buff2[len*2];
00913           char addbuff[len+1];
00914           SendMessage(MudInput,WM_GETTEXT,len+4,(LPARAM)(LPCSTR)buff);
00915           CHARRANGE cr;
00916           cr.cpMin = 0;
00917           cr.cpMax = strlen(buff);
00918           SendMessage(MudInput, EM_EXSETSEL, 0, (LPARAM)&cr);
00919           
00920           strcpy(addbuff,"\n");
00921           handle_input(buff);
00922 
00923         }
00924         break;
00925 
00926         default: 
00927             return  CallWindowProc(OldProc,hwnd,msg,wParam,lParam);
00928 
00929       }
00930         default: 
00931             return  CallWindowProc(OldProc,hwnd,msg,wParam,lParam);
00932 
00933     }
00934 
00935     return 0;
00936 }

Here is the call graph for this function:

void free_context HDC  context  ) 
 

Definition at line 970 of file nanomud-Main.c.

References hwnd.

Referenced by do_update_paint().

00971 {
00972     ReleaseDC(hwnd, context);
00973 }

void free_hdc_buf void   ) 
 

Definition at line 990 of file nanomud-Main.c.

References hdcbuf, hdcmap, and hold.

Referenced by do_bit().

00991 {
00992     SelectObject(hdcbuf, hold);
00993     DeleteObject(hdcmap);
00994     DeleteDC(hdcbuf);
00995 }    

HDC get_context  ) 
 

Definition at line 959 of file nanomud-Main.c.

References hdc, and MudMain.

Referenced by term_test_2().

00960 {
00961     HDC hdc;
00962     if (hwnd)
00963     {
00964         hdc = GetDC(MudMain);
00965         return hdc;
00966     }
00967     else
00968         return NULL;
00969 }

void get_scroll_pos  ) 
 

Definition at line 808 of file nanomud-Main.c.

References MudMain.

Referenced by terminal_resize(), and update_term().

00809 {
00810     SCROLLINFO sr;
00811     GetScrollInfo(MudMain, SB_VERT, &sr);
00812     
00813 }

void give_term_debug char *  to_echo,
  ...
 

Definition at line 1041 of file nanomud-Main.c.

References realize_lines(), and update_term().

Referenced by do_if(), do_nasty(), init_hash(), load_scripts(), and WinMain().

01042 {
01043     char buf[20000];
01044     int i;
01045     va_list args;
01046     va_start (args, to_echo);
01047     vsprintf (buf, to_echo, args);
01048     va_end (args);        
01049     to_echo = buf;
01050     char temp[strlen(to_echo) + 45];
01051     sprintf(temp, "TERM_DEBUG: \e[1;34m%s\e[0m\n", to_echo);
01052 
01053     realize_lines(temp);
01054     buf[0] = '\0';
01055     update_term();
01056 }    

Here is the call graph for this function:

void give_term_echo char *  to_echo,
  ...
 

Definition at line 1007 of file nanomud-Main.c.

References realize_lines(), and update_term().

Referenced by load_scripts(), parse_script(), and WinMain().

01008 {
01009     char buf[20000];
01010     int i;
01011     va_list args;
01012     va_start (args, to_echo);
01013     vsprintf (buf, to_echo, args);
01014     va_end (args);        
01015     to_echo = buf;
01016     char temp[strlen(to_echo) + 45];
01017     sprintf(temp, "TERM_ECHO: \e[1;32m%s\e[0m\n", to_echo);
01018 
01019     realize_lines(temp);
01020     buf[0] = '\0';
01021     update_term();
01022 }    

Here is the call graph for this function:

void give_term_error char *  to_echo,
  ...
 

Definition at line 1024 of file nanomud-Main.c.

References realize_lines(), and update_term().

Referenced by do_if(), handle_set_options(), HandleWinsockConnection(), load_settings(), and save_settings().

01025 {
01026     char buf[20000];
01027     int i;
01028     va_list args;
01029     va_start (args, to_echo);
01030     vsprintf (buf, to_echo, args);
01031     va_end (args);        
01032     to_echo = buf;
01033     char temp[strlen(to_echo) + 45];
01034     sprintf(temp, "TERM_ERROR: \e[1;31m%s\e[0m\n", to_echo);
01035 
01036     realize_lines(temp);
01037     buf[0] = '\0';
01038     update_term();
01039 }    

Here is the call graph for this function:

void GiveError char *  wrong,
BOOL  KillProcess
 

Definition at line 941 of file nanomud-Main.c.

References MudMain.

Referenced by _except_handler(), add_term(), check_string(), CreateAboutBox(), CreateCreditBox(), CreateSettings(), CreditProcedure(), do_nasty(), fix_line(), handle_aliases(), handle_class(), handle_path(), handle_triggers(), handle_var(), HandleWinsockConnection(), initwinsock(), log_html(), new_line(), save_aliases(), save_macros(), save_paths(), save_scripts(), save_triggers(), save_vars(), WindowProcedure(), WinMain(), write_buffer(), write_func_interp(), and write_shit_good().

00942 {
00943   if (wrong == NULL)
00944   {
00945     MessageBox(MudMain, "An unknown error has occured, please restart NanoMud and try again.", "NanoMud Error", MB_ICONSTOP | MB_OK);
00946     if (KillProcess)
00947         exit(0);
00948     else
00949         return;
00950   }
00951   
00952   MessageBox(MudMain, wrong, "NanoMud Error", MB_ICONSTOP | MB_OK);
00953   if (KillProcess)
00954       exit(0);
00955   else
00956       return;
00957 }

int HandleWinsockConnection HWND  hwnd,
char *  HostName
 

Definition at line 824 of file nanomud-Main.c.

References address, connected, session_data::connected, FALSE, give_term_error(), GiveError(), session_data::host, 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().

00825 {
00826 
00827   WORD wVersionRequested;          
00828   WSADATA wsaData;                 
00829   int err;                         
00830   char stuff[] = "";
00831   LPHOSTENT lpHost;
00832  
00833     
00834     address.sin_family=AF_INET;    
00835     address.sin_port = htons(this_session->port);
00836     if ( (sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET )
00837         exit(0); 
00838     if ( (host=gethostbyname(HostName)) == NULL )
00839     {
00840         give_term_error("Unable to find mud! %s", HostName);
00841         return;
00842         
00843     }
00844 
00845     address.sin_addr.s_addr=*((unsigned long *) host->h_addr);
00846     if ( (connect(sock,(struct sockaddr *) &address, sizeof(address))) != 0)
00847     {
00848         MessageBox(hwnd, "Unable to connect.", "Error", MB_OK);
00849         return 0;
00850     }
00851     this_session->rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
00852     if (this_session->rawSocket == SOCKET_ERROR)
00853     {
00854         GiveError("Unable to create raw socket in CheckPing().",FALSE);
00855         return ;
00856     }
00857     
00858     lpHost = gethostbyname(this_session->host);
00859     if (lpHost == NULL)
00860     {
00861         return ;
00862     }
00863     this_session->saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr));
00864     this_session->saDest.sin_family = AF_INET;
00865     this_session->saDest.sin_port = 0;
00866     //PingT = SetTimer(MudMain,1500 , 10000, NULL);
00867     //WindowProcedure (MudMain, WM_TIMER,0,0); /* Cheap hack for lazyness */
00868     this_session->connected = TRUE;
00869     char tempp[1000];
00870     sprintf(tempp, "TERM_ECHO: \e[1;32mConnected to %s:%d\e[0m\n", this_session->host, this_session->port);
00871     realize_lines(tempp);
00872     update_term();
00873     WSAAsyncSelect(sock,MudMain,WM_SOCKET, FD_READ|FD_CLOSE);
00874     connected = TRUE;
00875 
00876 
00877     return;
00878 }

Here is the call graph for this function:

void InitializeClient HINSTANCE  hInst  ) 
 

Definition at line 232 of file nanomud-Main.c.

References malloc, tbuf, and this_session.

Referenced by WinMain().

00233 {
00234     WNDCLASS wc;
00235     
00236     wc.cbClsExtra = 0;
00237     wc.cbWndExtra = 0;
00238     wc.hbrBackground =(HBRUSH) 7; 
00239     wc.lpfnWndProc = (WNDPROC) WindowProcedure;
00240     wc.lpszClassName = szClassName;
00241     wc.lpszMenuName = NULL;
00242     wc.hInstance = hInst;
00243     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00244     wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00245     wc.style = CS_DBLCLKS;
00246 
00247     RegisterClass(&wc);
00248     this_session = malloc(sizeof(*this_session));
00249     tbuf = malloc(sizeof(*tbuf));
00250     wc.cbClsExtra = 0;
00251     wc.cbWndExtra = 0;
00252     wc.hbrBackground =(HBRUSH) 1;
00253     wc.lpszClassName = "About";
00254     wc.lpfnWndProc = (WNDPROC) AboutProcedure;
00255     wc.lpszMenuName = NULL;
00256     wc.hInstance = hInst;
00257     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00258     wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00259     wc.style = CS_DBLCLKS;
00260 
00261     RegisterClass(&wc);
00262     
00263     wc.cbClsExtra = 0;
00264     wc.cbWndExtra = 0;
00265     wc.hbrBackground =(HBRUSH) 1;
00266     wc.lpszClassName = "Credit";
00267     wc.lpfnWndProc = (WNDPROC) CreditProcedure;
00268     wc.lpszMenuName = NULL;
00269     wc.hInstance = hInst;
00270     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00271     wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00272     wc.style = CS_DBLCLKS;
00273 
00274     RegisterClass(&wc);
00275     
00276     wc.cbClsExtra = 0;
00277     wc.cbWndExtra = 0;
00278     wc.hbrBackground =(HBRUSH) 1;
00279     wc.lpszClassName = "Settings";
00280     wc.lpfnWndProc = (WNDPROC) SettingsProcedure;
00281     wc.lpszMenuName = NULL;
00282     wc.hInstance = hInst;
00283     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00284     wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
00285     wc.style = CS_DBLCLKS;
00286 
00287     RegisterClass(&wc);
00288 
00289 
00290 }

void initwinsock  ) 
 

Definition at line 292 of file nanomud-Main.c.

References GiveError(), and wsaData.

Referenced by WinMain().

00293 {
00294   
00295   WORD wVersionRequested;
00296   WSADATA wsaData, pwsaData;
00297   int err,err2;
00298    
00299   wVersionRequested = MAKEWORD( 1, 1 );
00300   err = WSAStartup( wVersionRequested, &wsaData );
00301 
00302 
00303   if ( err != 0 )
00304       GiveError("Unable to find winsock.",1);
00305   
00306 
00307   return;
00308 } 

Here is the call graph for this function:

void richtextadd HWND  hwnd,
char *  add
 

Definition at line 879 of file nanomud-Main.c.

References hwnd.

00880 {
00881     int len;
00882     len = SendMessage(hwnd,WM_GETTEXTLENGTH,0,0);
00883     SendMessage(hwnd,EM_SETSEL,len,len);
00884     SendMessage(hwnd,EM_REPLACESEL,strlen(add),(LPARAM)(LPCSTR)add);
00885     return;
00886 }

void ScanWinsock HWND  hwnd  ) 
 

LRESULT APIENTRY WindowProcedure HWND  ,
UINT  ,
WPARAM  ,
LPARAM 
 

Definition at line 310 of file nanomud-Main.c.

References BLACK, bufcount, CloseWinsock(), cols, CreateAboutBox(), CreateCreditBox(), CreateSettings(), do_nasty(), do_update_paint(), do_url(), echo_off, echo_off_str, echo_on_str, EditProc(), export_to_html(), FlushBuffer(), FormatText(), FreeTerm(), g_hInst, get_hash(), 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, interp_mouse(), IS_IN_DEBUGGING_MODE, 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(), selecting, sock, tbuf, Terminal, terminal_resize(), this_session, TRUE, TRUE_BLACK, update_term(), WHITE, WM_SOCKET, poss::x, and poss::y.

00311 {
00312 
00313 
00314 
00315     switch (message)  
00316     {
00317 
00318         case WM_CREATE:
00319         {
00320                 HMENU hMenu, hSubMenu;
00321                 extern RECT mudrect;
00322                 RECT term;
00323                 SCROLLINFO sr;
00324 
00325 
00326 
00327                 hMenu = CreateMenu();
00328                 hSubMenu = CreatePopupMenu();
00329                 AppendMenu(hSubMenu, MF_STRING, ID_FILE_NEW, "&New");
00330                 AppendMenu(hSubMenu, MF_STRING |MF_POPUP, ID_FILE_CLOSE, "&Close");
00331                 AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, "&Open");
00332                 AppendMenu(hSubMenu, MF_STRING, ID_FILE_DISCONNECT, "&Disconnect");
00333                 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00334                 AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXPORT_HTML, "&Export HTML log");
00335                 AppendMenu(hSubMenu, MF_STRING |MF_POPUP|MF_GRAYED, ID_FILE_EXPORT_TEXT, "E&xport TEXT log");
00336                 AppendMenu(hSubMenu, MF_STRING |MF_POPUP|MF_GRAYED, ID_FILE_EXPORT_ANSI, "Ex&port ANSI log");
00337                 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00338                 AppendMenu(hSubMenu, MF_STRING , ID_FILE_IMPORT_ANSI, "I&mport ANSI/TEXT log");
00339                 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00340                 AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
00341                 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
00342                 SetMenu(hwnd, hMenu);
00343                 hSubMenu = CreatePopupMenu();
00344                 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_FIND, "&Find");
00345                 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_FIND_NEXT, "Find &Next");
00346                 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_PASTE, "&Paste");
00347                 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_COPY, "&Copy");
00348                 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_SEND, "&Send File to MUD");
00349                 AppendMenu(hSubMenu, MF_STRING, ID_EDIT_SALL, "S&elect All");
00350                 AppendMenu(hMenu, MF_STRING|MF_POPUP, (UINT)hSubMenu, "&Edit");
00351                 SetMenu(hwnd, hMenu);
00352                 hSubMenu = CreatePopupMenu();
00353                 AppendMenu(hSubMenu, MF_STRING, ID_SETTINGS_CONFIGURE, "&Configure");
00354                 AppendMenu(hSubMenu, MF_STRING, ID_SETTINGS_STATUS, "C&lient Status");
00355                 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00356                 AppendMenu(hSubMenu, MF_STRING, ID_SETTINGS_OPTIONS, "&Options");
00357                 AppendMenu(hMenu, MF_STRING |MF_POPUP, (UINT)hSubMenu, "&Settings");
00358                 SetMenu(hwnd, hMenu);
00359                 hSubMenu = CreatePopupMenu();
00360                 AppendMenu(hSubMenu, MF_STRING, ID_HELP_HELP, "&Help");
00361                 AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "&About");
00362                 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
00363                 AppendMenu(hSubMenu, MF_STRING, ID_HELP_CREDITS, "&Credits");
00364                 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");
00365                 SetMenu(hwnd, hMenu);
00366                 tbuf->hdc = GetDC(MudMain);
00367                 GetClientRect(hwnd, &mudrect);
00368                 GetClientRect(Terminal, &term);
00369                 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);
00370                 SendMessage(MudInput, EM_SETEVENTMASK, 0,0);
00371                 
00372                 OldProc = (WNDPROC) SetWindowLong(MudInput,GWL_WNDPROC,(LONG)EditProc);
00373                 //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);
00374                 //SendMessage(MudStatus, EM_SETEVENTMASK,0,0);
00375                 tbuf->hwnd = hwnd;
00376                 //ShowWindow(MudInput, SW_SHOW);
00377 
00378     }
00379     break;
00380     
00381     case WM_SIZE:
00382     {
00383         RECT mudwin;
00384         
00385         GetClientRect(MudMain, &mudwin);   
00386         MoveWindow(MudInput, mudwin.left, mudwin.bottom-20, mudwin.right, 20, TRUE);
00387         terminal_resize ();
00388         
00389         break;
00390      
00391     }
00392         
00393     case WM_COMMAND:
00394         switch(LOWORD(wParam))
00395         {
00396             
00397             case ID_EDIT_FIND:
00398                 break;
00399             
00400             case ID_EDIT_FIND_NEXT:
00401                 break;
00402             
00403             case ID_EDIT_PASTE:
00404                 break;
00405             
00406             case ID_EDIT_COPY:
00407                 break;
00408             
00409             case ID_EDIT_SEND:
00410                 break;
00411             
00412             case ID_EDIT_SALL:
00413                 break;
00414                 
00415             
00416             case ID_FILE_EXIT:
00417             {
00418                 char buf[100];
00419                 if (IS_IN_DEBUGGING_MODE == 1)
00420                     sprintf(buf, "Thank you for using NanoMud v.%s.",Mud_client_Version);
00421                 else
00422                     sprintf(buf, "Thank you for using NanoMud v.%s.",Mud_client_Version);
00423  
00424                 MessageBox(hwnd, buf, "NanoMud", MB_OK);
00425                 save_scripts();
00426                 PostQuitMessage (0);
00427                 break;
00428             }
00429             case ID_FILE_OPEN:
00430                 HandleWinsockConnection(hwnd, this_session->host);
00431                 break;
00432       
00433             case ID_FILE_DISCONNECT:
00434                 CloseWinsock(hwnd, this_session->host);
00435                 break;
00436       
00437             case ID_FILE_EXPORT_HTML:
00438                 export_to_html();
00439                 break;
00440 
00441             case ID_FILE_EXPORT_TEXT:
00442                 break;
00443   
00444             case ID_FILE_EXPORT_ANSI:
00445                 break;
00446   
00447             case ID_FILE_IMPORT_ANSI:
00448                 do_nasty();
00449                 update_term();
00450                 break;
00451   
00452              case ID_FILE_CLOSE:
00453              {
00454                 this_session->proc = &give_term_echo;
00455                 this_session->proc("Testing moved to import.");
00456                 break;
00457              }
00458 
00459              case ID_FILE_NEW:
00460                 break;
00461               
00462              case ID_SETTINGS_CONFIGURE:
00463                 CreateSettings();
00464                 break;
00465 
00466              case ID_SETTINGS_STATUS:
00467                 MessageBox(hwnd, "Client Status...not working?", "NanoMud", MB_OK);
00468                 break;
00469   
00470              case ID_SETTINGS_OPTIONS:
00471                 MessageBox(hwnd, "Options: StubFunction", "NanoMud", MB_OK);
00472                 break;
00473                 
00474              case ID_HELP_HELP:
00475                 do_url("http://www.nanobit.net");
00476                 break;
00477      
00478              case ID_HELP_ABOUT:
00479                 CreateAboutBox();
00480                 break;
00481       
00482              case ID_HELP_CREDITS:
00483                 CreateCreditBox();  
00484                 break;
00485 
00486         }
00487         case WM_SETFOCUS:
00488         
00489 
00490             if (IsWindow(MudAbout))
00491                 break;
00492             else if (IsWindow(MudCredit))
00493                 break;
00494             else if (IsWindow(MudSettings))
00495                 break;
00496             else
00497             {
00498              //   InvalidateRect(MudMain, NULL, TRUE);
00499                 
00500                 SetFocus(MudInput);
00501             }    
00502 
00503             break;
00504         case WM_LBUTTONDOWN:
00505         {
00506             
00507             int x,y=0;
00508             y = LOWORD(lParam);
00509             x = HIWORD(lParam);
00510             selecting = TRUE;
00511             interp_mouse(x/13,(y-8)/8,MOUSE_LEFT);
00512             return DefWindowProc(hwnd, message, wParam, lParam);
00513           
00514         }
00515         break;
00516 
00517         case WM_RBUTTONDOWN:
00518         {
00519             int x,y=0;
00520             y = LOWORD(lParam);
00521             x = HIWORD(lParam);
00522             interp_mouse(x/13,(y-8)/8,MOUSE_RIGHT);
00523           return DefWindowProc(hwnd, message, wParam, lParam);
00524         }
00525         break;
00526         case WM_MBUTTONDOWN:
00527         {
00528             int x,y=0;
00529             y = LOWORD(lParam);
00530             x = HIWORD(lParam);
00531             interp_mouse(x/13,(y-8)/8,MOUSE_MIDDLE);
00532           return DefWindowProc(hwnd, message, wParam, lParam);
00533         }
00534         break;
00535 
00536         case WM_MOUSEMOVE:
00537         {
00538             
00539 
00540             if (selecting)
00541             {
00542                 int x,y=0;
00543                 y=LOWORD(lParam);
00544                 x=HIWORD(lParam);
00545                 interp_mouse(x/13,(y-8)/8,MOUSE_LEFT);
00546             }
00547             else
00548             {
00549                 int x,y=0;
00550                 char buf[100];
00551                 y=LOWORD(lParam);
00552                 x=HIWORD(lParam);
00553                 extern  poss pos;
00554                 pos.x = x/13;
00555                 pos.y = y/8;
00556                 //set_mouse_pos((x-13)/13,(y-8)/8);
00557                 sprintf(buf, "%-20s", " ");
00558                 FlushBuffer(buf, BLACK, TRUE_BLACK);
00559                 sprintf(buf, "row: %d, col: %d", (x)/13,(y)/8);
00560         
00561                 tbuf->y_end = rows * 13-15;
00562                 tbuf->x_end = cols * 4 - 50;
00563     
00564                 FlushBuffer(buf, WHITE, BLACK);
00565                 update_term();
00566                 
00567             }    
00568             
00569 
00570             
00571             break;
00572         }
00573         break;
00574         
00575         case WM_LBUTTONUP:
00576             selecting = FALSE;
00577             break;
00578 
00579 
00580             
00581              
00582         case WM_SOCKET:
00583                                    
00584                 switch(LOWORD(lParam))
00585                 {
00586                     case FD_READ:
00587                     {
00588                     
00589                      
00590                         char readbuff[22460]="";
00591                         char Buf[22460]="";
00592                         char buf[22460]="";
00593                         char readbuff2[22460]="";
00594                         char readbuffer[22460]="";
00595                         char *ansi;
00596                         int err=10;
00597                         readbuff[0]='\0';
00598                         err = 1;
00599                         err = recv(sock, readbuff, 2460, 0); /* Gonna read 1460 bytes at a time */
00600                                                
00601                                                 
00602                         
00603                         if (err != 0)
00604                         {
00605 
00606 
00607                             int buflen=strlen(readbuff);
00608                             Buf[0] = '\0';
00609                             ansi = Buf;
00610                             if (strstr(readbuff, echo_off_str))
00611                             {
00612                                 strcpy(readbuffer,readbuff);
00613                                 echo_off = TRUE;
00614 
00615                                 readbuffer[strlen(readbuff)] = readbuff[buflen - strlen(echo_off_str)];
00616                                 readbuffer[strlen(readbuff)+1] = '\0';
00617                                 strcpy(readbuff, readbuffer);
00618                             }
00619                             if (strstr(readbuff, echo_on_str))
00620                             {
00621                                 strcpy(readbuffer,readbuff);
00622                                 echo_off = FALSE;
00623                                 SendMessage(MudInput, EM_SETEVENTMASK, 0,0);
00624                                 readbuffer[strlen(readbuff)]=readbuff[buflen-strlen(echo_on_str)];
00625                                 readbuffer[strlen(readbuff)+1]='\0';
00626                                 strcpy(readbuff, readbuffer);
00627                             }
00628                             if (strstr(readbuff, go_ahead_str))
00629                             {
00630                                 strcpy(readbuffer,readbuff);
00631                                 readbuffer[strlen(readbuff)]=readbuff[buflen-strlen(go_ahead_str)];
00632                                 readbuffer[strlen(readbuff)+1]='\0';
00633                                 strcpy(readbuff,readbuffer);
00634                             }
00635                             get_hash(readbuff);
00636                             ParseLines(readbuff);
00637 
00638                             readbuff[0] = '\0';
00639                             readbuffer[0]='\0';
00640 
00641                         }
00642                         else
00643                         {
00644                             GiveError("Unknown Error with Winsock recv();",1);
00645                             return;
00646                         }
00647                         
00648                     }
00649                     break;
00650                     
00651                     case FD_CLOSE:
00652                     {
00653                         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. :)", TRUE);
00654                         break;
00655                     } 
00656                     default:
00657                         return DefWindowProc (hwnd, message, wParam, lParam);
00658                         break;
00659                                                         
00660                 }
00661                 break;
00662               
00663         case WM_DESTROY:
00664       
00665             FreeTerm();
00666             return_usage();
00667             KillTimer(MudMain, PingT);
00668             WSACleanup();
00669             PostQuitMessage (0);       
00670             break;
00671 
00672                 
00673 
00674            
00675         case WM_PAINT:
00676         {
00677 
00678             //if (this_session->connected == TRUE)
00679             //{
00680             
00681                 
00682                 PAINTSTRUCT p;
00683                 HDC hdc = BeginPaint(hwnd,&p);
00684 
00685                 do_update_paint(hdc, (p.rcPaint.left-8)/8, (p.rcPaint.top-13)/13,(p.rcPaint.right-8-1)/8,
00686                     (p.rcPaint.bottom-13-1)/13);
00687             //}
00688             //else
00689             //    return DefWindowProc(hwnd, message, wParam, lParam);
00690             break;
00691  
00692 
00693 /*             if (this_session->connected == TRUE)
00694              {
00695                  update_term();
00696                  break;
00697              }
00698              else
00699              {
00700                  return DefWindowProc(hwnd, message,wParam, lParam);
00701              }
00702              break;       */
00703 
00704         }
00705 
00706 
00707         case WM_VSCROLL:
00708             switch(LOWORD(wParam))
00709             { 
00710 
00711                 case SB_TOP:
00712                     scroll_term(+1,0);
00713                 case SB_THUMBPOSITION:
00714                 case SB_THUMBTRACK:
00715                     scroll_term(1, (LONG)HIWORD(wParam));
00716                     break;
00717                 case SB_PAGEUP:
00718                     scroll_term(0, -(bufcount / 10));
00719                     break;
00720                 case SB_PAGEDOWN:
00721                     scroll_term(0, bufcount / 10);
00722                     break;
00723                 case SB_BOTTOM:
00724                     scroll_term(-1,0);
00725                 case SB_LINEDOWN:
00726                     scroll_term(0,+1);
00727                     break;
00728                 case SB_LINEUP:
00729                     scroll_term(0,-1);
00730                     break;
00731                 default:
00732                     return DefWindowProc(hwnd, message,wParam,lParam);
00733                     break;
00734             }
00735             break;
00736             
00737             case WM_MOUSEWHEEL:
00738             {
00739                 int pos=0;
00740                 int way=0;
00741                 pos += (short)HIWORD(wParam);
00742                 
00743                 if (pos < 0)
00744                     way = 0;
00745                 else if (pos > 0)
00746                     way = 1;
00747                 scroll_term(0, way == 0 ? +50 : -50);
00748                 
00749                 break;
00750             }
00751             
00752         
00753      
00754             
00755         
00756 
00757         default: 
00758            FormatText(MudInput);                                
00759            return DefWindowProc (hwnd, message, wParam, lParam);
00760            break;
00761     
00762     }
00763 
00764     return 0;
00765 }

Here is the call graph for this function:

int WINAPI WinMain HINSTANCE  hThisInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpszArgument,
int  nFunsterStil
 

Definition at line 105 of file nanomud-Main.c.

References termbuf::buffer, check_ping(), session_data::colour, create_hdc_buf(), FormatText(), g_hInst, give_term_debug(), give_term_echo(), GiveError(), termbuf::hdc, hdc, hf, session_data::host, html_log, hwnd, init_scripts(), InitializeClient(), initwinsock(), load_scripts(), load_settings(), LOG(), malloc, session_data::max_buffer, MudInput, MudMain, mudrect, session_data::name, session_data::port, save_settings(), send_buff, sock, szClassName, tbuf, TERMBUF, Terminal, terminal_initialize(), session_data::termlist, this_session, tready, TRUE, and WM_SOCKET.

00110 {
00111 
00112 //write_shit_good();
00113 //exit(0);
00114     MSG messages;
00115     long lfHeight=13;
00116     extern HFONT hf;
00117     extern RECT mudrect;
00118     
00119     extern HDC chdc;
00120     DWORD handler = (DWORD)_except_handler;
00121     SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)handler);
00122 
00123     
00124 
00125     LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL;
00126     DWORD stackSize = 0;
00127     int theArg;
00128     DWORD dwCreationFlags = 0;
00129     DWORD targetThreadID;
00130 
00131     _beginthreadex ((void *) lpThreadAttributes,(unsigned) stackSize,(unsigned (_stdcall *) (void *))check_ping,(void *) &theArg,(unsigned) dwCreationFlags, (unsigned *) &targetThreadID);
00132    
00133     LoadLibrary("RichEd32.Dll");
00134     
00135     InitializeClient(hThisInstance);
00136     g_hInst = hThisInstance;
00137       MudMain = CreateWindow(szClassName,"NanoMud Main Window -- Nanobit Software (C) 2004",
00138              WS_SYSMENU|WS_VSCROLL|WS_MINIMIZEBOX|WS_MAXIMIZE|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_SIZEBOX,
00139              0,0,800,600,0,0,hThisInstance,0);
00140    
00141    
00142     hwnd = MudMain;
00143     initwinsock();
00144 
00145     WSAAsyncSelect(sock,MudMain,WM_SOCKET, FD_CLOSE|FD_READ);             
00146     this_session->name = "fleh";
00147     this_session->host = "hub.seark.net";
00148     this_session->port = 4000;
00149     this_session->colour = TRUE;
00150     this_session->max_buffer = 1000010;
00151     this_session->termlist = (TERMBUF **)malloc(this_session->max_buffer * sizeof(*this_session->termlist));
00152 
00153 
00154     tbuf->x_start = 0;
00155     tbuf->x_end = 0;
00156     tbuf->y_start = 0; 
00157     tbuf->y_end = 0;
00158     char rawr[100000];
00159     terminal_initialize();  
00160 
00161       
00162     int runner;
00163     for (runner=0;runner<=100;runner++)
00164     {
00165         send_buff[runner] = malloc(sizeof(char));
00166         send_buff[runner]->buffer = '\0';
00167     }
00168     if (tbuf == NULL)
00169         GiveError("Tbuf->buffer failed to initialize", TRUE);
00170           
00171     FILE *fp;
00172     if ((fp = fopen(html_log, "a")) == NULL)
00173     {
00174         LOG("Unable to open html logfile.");
00175         return;
00176     }
00177     fprintf(fp, "<body bgcolor=\"black\"><font face=\"Courier New\"><pre>\n");
00178     fclose(fp);
00179     HDC hdc;
00180     hdc = GetDC(MudMain);
00181    
00182     tbuf->hdc = hdc;
00183     UpdateWindow(MudMain);
00184     hf = CreateFont(13, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, DEFAULT_QUALITY, 0, "Courier");
00185     SetBkColor(hdc,RGB(0,0,0)); 
00186     SetTextColor(hdc, RGB(0,128,0)); 
00187 
00188     GetClientRect(Terminal, &mudrect);
00189  
00190     FormatText(MudInput);
00191 
00192    
00193     give_term_echo("Welcome to nanomud!\n");
00194     init_scripts();
00195     give_term_debug("Loading scripts.");
00196     load_scripts();
00197 //   init_hash(65000);
00198     give_term_debug("Loading settings.");
00199     load_settings();
00200     save_settings();
00201 
00202     create_hdc_buf();
00203   
00204     tready=TRUE; /* HACKHACK */
00205     ShowWindow(MudMain,SW_SHOW); 
00206     while (GetMessage (&messages, NULL, 0, 0))
00207     {
00208         TranslateMessage(&messages);
00209         DispatchMessage(&messages);
00210     }
00211 
00212  
00213     return messages.wParam;
00214 }

Here is the call graph for this function:


Variable Documentation

struct sockaddr_in address
 

Definition at line 46 of file nanomud-Main.c.

Referenced by