1 /* $Id: xpilots.cpp,v 5.1 2001/05/28 00:19:25 dik Exp $
2 *
3 * XPilot, a multiplayer gravity war game. Copyright (C) 1991-2001 by
4 *
5 * Bj�rn Stabell <bjoern@xpilot.org>
6 * Ken Ronny Schouten <ken@xpilot.org>
7 * Bert Gijsbers <bert@xpilot.org>
8 * Dick Balaska <dick@xpilot.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 /***************************************************************************\
26 * xpilots.cpp - The main xpilots Application class *
27 * *
28 \***************************************************************************/
29
30 #include "stdafx.h"
31 #include "xpilots.h"
32 #include "xpilotsDlg.h"
33
34 extern "C" bool Parser(int argc, char **argv);
35
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #undef THIS_FILE
39 static char THIS_FILE[] = __FILE__;
40 #endif
41
42 /////////////////////////////////////////////////////////////////////////////
43 // CXpilotsApp
44
BEGIN_MESSAGE_MAP(CXpilotsApp,CWinApp)45 BEGIN_MESSAGE_MAP(CXpilotsApp, CWinApp)
46 //{{AFX_MSG_MAP(CXpilotsApp)
47 // NOTE - the ClassWizard will add and remove mapping macros here.
48 // DO NOT EDIT what you see in these blocks of generated code!
49 //}}AFX_MSG
50 ON_COMMAND(ID_HELP, CWinApp::OnHelp)
51 END_MESSAGE_MAP()
52
53 /////////////////////////////////////////////////////////////////////////////
54 // CXpilotsApp construction
55
56 CXpilotsApp::CXpilotsApp()
57 {
58 // TODO: add construction code here,
59 // Place all significant initialization in InitInstance
60 }
61
62 /////////////////////////////////////////////////////////////////////////////
63 // The one and only CXpilotsApp object
64
65 CXpilotsApp theApp;
66
67 /////////////////////////////////////////////////////////////////////////////
68 // CXpilotsApp initialization
69
InitInstance()70 BOOL CXpilotsApp::InitInstance()
71 {
72 if (!strncmp(m_lpCmdLine, "/ServerOpts", 11))
73 {
74 char* s = strdup(m_lpCmdLine);
75 char* seps = " ,\t\n";
76 char* token = strtok(s, seps); // skip the /ServerOpts
77 token = strtok(NULL, seps); // get the file name
78 char* fname = "ServerOpts.txt";
79 if (token && strlen(token))
80 fname = token;
81 char* parms[2] = {"XPilotServer", "-help"};
82 FILE* fp = freopen(fname, "w", stdout);
83 Parser(2, parms);
84 fclose(fp);
85 free(s);
86 return(FALSE);
87
88 }
89 if (!AfxSocketInit())
90 {
91 AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
92 return FALSE;
93 }
94
95 // Standard initialization
96 // If you are not using these features and wish to reduce the size
97 // of your final executable, you should remove from the following
98 // the specific initialization routines you do not need.
99
100 #ifdef _AFXDLL
101 Enable3dControls(); // Call this when using MFC in a shared DLL
102 #else
103 Enable3dControlsStatic(); // Call this when linking to MFC statically
104 #endif
105
106 CXpilotsDlg dlg;
107 m_pMainWnd = &dlg;
108 int nResponse = dlg.DoModal();
109 if (nResponse == IDOK)
110 {
111 // TODO: Place code here to handle when the dialog is
112 // dismissed with OK
113 }
114 else if (nResponse == IDCANCEL)
115 {
116 // TODO: Place code here to handle when the dialog is
117 // dismissed with Cancel
118 }
119
120 // Since the dialog has been closed, return FALSE so that we exit the
121 // application, rather than start the application's message pump.
122 return FALSE;
123 }
124
ExitInstance()125 int CXpilotsApp::ExitInstance()
126 {
127 // TODO: Add your specialized code here and/or call the base class
128 WSACleanup();
129 return CWinApp::ExitInstance();
130 }
131
132 // interface routines to the xpilot "C" code
133 extern "C"
_Trace(char * lpszFormat,long a,long b,long c,long d,long e)134 void _Trace(char* lpszFormat, long a, long b, long c, long d, long e)
135 {
136 AfxTrace(lpszFormat, a, b, c, d, e);
137 }
138
139 extern "C" const char* GetWSockErrText(int error);
140 extern "C"
_GetWSockErrText(int error)141 const char* _GetWSockErrText(int error)
142 {
143 return(GetWSockErrText(error));
144 }
145
146 extern "C" int server_running = FALSE;
147