Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Main.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: main.cpp
7  AUTHOR: John DiCamillo
8 */
9 
10 
11 #include "MemDebug.h"
12 #include "Starshatter.h"
13 #include "StarServer.h"
14 #include "Authorization.h"
15 #include "HUDView.h"
16 
17 #include "NetHost.h"
18 #include "NetAddr.h"
19 #include "NetLayer.h"
20 #include "NetBrokerClient.h"
21 #include "NetClient.h"
22 #include "HttpClient.h"
23 
24 #include "Color.h"
25 #include "DataLoader.h"
26 #include "Pcx.h"
27 #include "MachineInfo.h"
28 #include "Encrypt.h"
29 #include "FormatUtil.h"
30 #include "ParseUtil.h"
31 #include "Random.h"
32 
33 // +--------------------------------------------------------------------+
34 // WinMain
35 // +--------------------------------------------------------------------+
36 
37 extern FILE* ErrLog;
38 extern int VD3D_describe_things;
39 int dump_missions = 0;
40 
41 #ifdef STARSHATTER_DEMO_RELEASE
42 const char* versionInfo = "5.0 DEMO";
43 #else
44 const char* versionInfo = "5.0.5";
45 #endif
46 
47 static void PrintLogHeader()
48 {
49  Text sTime = FormatTimeString();
50 
51  Print("+====================================================================+\n");
52  Print("| STARSHATTER %-25s%29s |\n", versionInfo, sTime.data());
53 
57 }
58 
59 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
60 LPSTR lpCmdLine, int nCmdShow)
61 {
62  int result = 0;
63  int test_mode = 0;
64  int do_server = 0;
65 
66  if (strstr(lpCmdLine, "-server"))
67  ErrLog = fopen("serverlog.txt", "w");
68  else
69  ErrLog = fopen("errlog.txt", "w");
70 
71  PrintLogHeader();
72 
73  if (strstr(lpCmdLine, "-test")) {
74  Print(" Request TEST mode\n");
75  test_mode = 1;
76  }
77 
78  if (strstr(lpCmdLine, "-fps")) {
79  HUDView::ShowFPS(true);
80  }
81 
82  if (strstr(lpCmdLine, "-dump")) {
83  Print(" Request dump dynamic missions\n");
84  dump_missions = 1;
85  }
86 
87  if (strstr(lpCmdLine, "-lan")) {
88  Print(" Request LAN ONLY mode\n");
90  }
91 
92  if (strstr(lpCmdLine, "-server")) {
93  do_server = 1;
94  Print(" Request Standalone Server Mode\n");
95  }
96 
97  char* d3dinfo = strstr(lpCmdLine, "-d3d");
98  if (d3dinfo) {
99  int n = d3dinfo[4] - '0';
100 
101  if (n >= 0 && n <= 5)
103 
104  Print(" D3D Info Level: %d\n", VD3D_describe_things);
105  }
106  else {
108  }
109 
110 
111  // FREE VERSION - AUTHORIZATION DISABLED
112  /*
113 ::Print(" Checking authorization codes...\n");
114 if (!Authorization::IsUserAuthorized()) {
115  if (!DataLoader::GetLoader()) {
116  DataLoader::Initialize();
117  DataLoader::GetLoader()->EnableDatafile("content.dat");
118  }
119 
120  Game* game = new Game();
121  game->InitContent();
122 
123  MessageBox(0, FormatTextEscape(Game::GetText("main.auth-invalid")).data(),
124  Game::GetText("main.title.error").data(), MB_OK);
125  ::Print(" Not authorized.\n");
126 
127  delete game;
128  DataLoader::Close();
129 }
130 else {
131  ::Print(" Authorized\n");
132  */
133  try {
134  NetLayer net;
135 
136  if (do_server) {
137  StarServer* server = new(__FILE__,__LINE__) StarServer();
138 
139  if (server->Init(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
140  result = server->Run();
141 
142  Print("\n+====================================================================+\n");
143  Print(" Begin Shutdown...\n");
144 
145  delete server;
146  }
147 
148  else {
149  Starshatter* stars = 0;
150 
151  stars = new(__FILE__,__LINE__) Starshatter;
152  stars->SetTestMode(test_mode);
153 
154  if (stars->Init(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
155  result = stars->Run();
156 
157  Print("\n+====================================================================+\n");
158  Print(" Begin Shutdown...\n");
159 
160  delete stars;
161  }
162 
163  Token::close();
164 
165  if (*Game::GetPanicMessage())
166  MessageBox(0, Game::GetPanicMessage(), "Starshatter - Error", MB_OK);
167  }
168 
169  catch (const char* msg) {
170  Print(" FATAL EXCEPTION: '%s'\n", msg);
171  }
172  /* } */
173 
174  Memory::Stats();
177 
178  Print("+====================================================================+\n");
179  Print(" END OF LINE.\n");
180 
181  fclose(ErrLog);
182 
183  return result;
184 }
185 
186