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 const char* versionInfo = "5.1.66";
42 
43 static void PrintLogHeader()
44 {
45  Text sTime = FormatTimeString();
46 
47  Print("+====================================================================+\n");
48  Print("| STARSHATTER %-25s%29s |\n", versionInfo, sTime.data());
49 
53 }
54 
55 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
56 LPSTR lpCmdLine, int nCmdShow)
57 {
58  int result = 0;
59  int test_mode = 0;
60  int do_server = 0;
61 
62  if (strstr(lpCmdLine, "-server"))
63  ErrLog = fopen("serverlog.txt", "w");
64  else
65  ErrLog = fopen("errlog.txt", "w");
66 
67  PrintLogHeader();
68 
69  if (strstr(lpCmdLine, "-test")) {
70  Print(" Request TEST mode\n");
71  test_mode = 1;
72  }
73 
74  if (strstr(lpCmdLine, "-fps")) {
75  HUDView::ShowFPS(true);
76  }
77 
78  if (strstr(lpCmdLine, "-dump")) {
79  Print(" Request dump dynamic missions\n");
80  dump_missions = 1;
81  }
82 
83  if (strstr(lpCmdLine, "-lan")) {
84  Print(" Request LAN ONLY mode\n");
86  }
87 
88  if (strstr(lpCmdLine, "-server")) {
89  do_server = 1;
90  Print(" Request Standalone Server Mode\n");
91  }
92 
93  char* d3dinfo = strstr(lpCmdLine, "-d3d");
94  if (d3dinfo) {
95  int n = d3dinfo[4] - '0';
96 
97  if (n >= 0 && n <= 5)
99 
100  Print(" D3D Info Level: %d\n", VD3D_describe_things);
101  }
102  else {
104  }
105 
106 
107  // FREE VERSION - AUTHORIZATION DISABLED
108  /*
109 ::Print(" Checking authorization codes...\n");
110 if (!Authorization::IsUserAuthorized()) {
111  if (!DataLoader::GetLoader()) {
112  DataLoader::Initialize();
113  DataLoader::GetLoader()->EnableDatafile("content.dat");
114  }
115 
116  Game* game = new Game();
117  game->InitContent();
118 
119  MessageBox(0, FormatTextEscape(Game::GetText("main.auth-invalid")).data(),
120  Game::GetText("main.title.error").data(), MB_OK);
121  ::Print(" Not authorized.\n");
122 
123  delete game;
124  DataLoader::Close();
125 }
126 else {
127  ::Print(" Authorized\n");
128  */
129  try {
130  NetLayer net;
131 
132  if (do_server) {
133  StarServer* server = new(__FILE__,__LINE__) StarServer();
134 
135  if (server->Init(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
136  result = server->Run();
137 
138  Print("\n+====================================================================+\n");
139  Print(" Begin Shutdown...\n");
140 
141  delete server;
142  }
143 
144  else {
145  Starshatter* stars = 0;
146 
147  stars = new(__FILE__,__LINE__) Starshatter;
148  stars->SetTestMode(test_mode);
149 
150  if (stars->Init(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
151  result = stars->Run();
152 
153  Print("\n+====================================================================+\n");
154  Print(" Begin Shutdown...\n");
155 
156  delete stars;
157  }
158 
159  Token::close();
160 
161  if (*Game::GetPanicMessage())
162  MessageBox(0, Game::GetPanicMessage(), "Starshatter - Error", MB_OK);
163  }
164 
165  catch (const char* msg) {
166  Print(" FATAL EXCEPTION: '%s'\n", msg);
167  }
168  /* } */
169 
170  Memory::Stats();
173 
174  Print("+====================================================================+\n");
175  Print(" END OF LINE.\n");
176 
177  fclose(ErrLog);
178 
179  return result;
180 }
181 
182