-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
220 lines (188 loc) · 5.45 KB
/
main.cpp
File metadata and controls
220 lines (188 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//
// main.cpp
// Project Spitfire
//
// Copyright (c) 2013 Daizee (rensiadz at gmail dot com)
//
// This file is part of Spitfire.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "stdafx.h"
#include "structs.h"
#include "funcs.h"
#include "Server.h"
#include "amf3.h"
#ifndef WIN32
void sigfunc(int sig_no);
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <iostream>
#include <signal.h>
BOOL WINAPI ConsoleHandler(DWORD CEvent);
#endif
Server * gserver = 0;
int _tmain(int argc, _TCHAR* argv[])
{
#ifndef WIN32
struct sigaction sa={0};
sa.sa_handler = &sigfunc;
sigaction(SIGINT, &sa, 0);
sigaction(SIGHUP, &sa, 0);
sigaction(SIGUSR1, &sa, 0);
sigaction(SIGUSR2, &sa, 0);
#else
if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
{
// unable to install handler...
// display message to the user
printf("Unable to install handler!\n");
return -1;
}
#endif
// Read a query result set
// while (res->next()) {
// cout << "email = " << res->getString("email") << endl; // getInt(1) returns the first column
// }
//Create Server Object
gserver = new Server();
gserver->serverstatus = SERVERSTATUS_STARTING;
try {
//Initialize server and load config files
if (!gserver->Init()) { system("pause"); return 0; }
//Connect to SQL server
if (!gserver->ConnectSQL()) { system("pause"); return 0; }
//Open sockets
if (!gserver->InitSockets()) { system("pause"); return 0; }
}
catch (std::exception& e)
{
gserver->consoleLogger->information(Poco::format("Init Exception: %s", (string)e.what()));
system("pause");
return 0;
}
catch(...)
{
gserver->consoleLogger->information("Init Exception.");
system("pause");
return 0;
}
// /*
// The MySQL Connector/C++ throws three different exceptions:
//
// - sql::MethodNotImplementedException (derived from sql::SQLException)
// - sql::InvalidArgumentException (derived from sql::SQLException)
// - sql::SQLException (derived from std::runtime_error)
// */
// cout << "# ERR: SQLException in " << __FILE__;
// cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
// // Use what(), getErrorCode() and getSQLState()
// cout << "# ERR: " << e.what();
// cout << " (MySQL error code: " << e.getErrorCode();
// cout << ", SQLState: " << e.getSQLState() << " )" << endl;
// cout << "not ok 1 - examples/statement.cpp" << endl;
//
// ResultSet * res = gserver->sql1->QueryRes("SELECT * from account");
// cout << res->rowsCount() << endl;
// while (res->next()) {
// cout << "password = " << res->getString("password") << endl; // getInt(1) returns the first column
// }
//Server is finally online here
gserver->serverstatus = SERVERSTATUS_ONLINE;
// Run the server until stopped.
try
{
gserver->run();
}
catch (Poco::Data::MySQL::StatementException * e)
{
gserver->consoleLogger->error(Poco::format("Random SQL Exception: %s", e->displayText() ));
}
while (gserver->TimerThreadRunning)
{
Sleep(1);
}
//ResultSet * res = server->GetAccountSQL()->QueryRes("SELECT * from account");
//while (res->next()) {
// cout << "password = " << res->getString("password") << endl; // getInt(1) returns the first column
//}
//gserver->ConLog()->Log("Shutting down");
gserver->stop_all();
delete gserver;
system("pause");
return 0;
}
#ifndef WIN32
void sigfunc(int sig_no)
{
printf("Signal received: %d\n", sig_no);
// if (sig_no == SIGSEGV)
// {
// Log("Seg fault onoes!");
// }
/*else*/ if (sig_no == SIGINT)
{
printf("Interrupt request\n");
serverrunning = false;
//LoginServer->serverrunning = false;
}
else if (sig_no == SIGHUP)
{
printf("Rehash Signal\n");
}
else if (sig_no == SIGUSR1)
{
printf("user1 Signal\n");
}
else if (sig_no == SIGUSR2)
{
printf("user2 Signal\n");
}
}
#else
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
char mesg[128];
switch(CEvent)
{
case CTRL_C_EVENT:
// MessageBox(NULL,
// _T("CTRL+C received!"),_T("CEvent"),MB_OK);
gserver->Shutdown();
break;
case CTRL_BREAK_EVENT:
// MessageBox(NULL,
// _T("CTRL+BREAK received!"),_T("CEvent"),MB_OK);
break;
case CTRL_CLOSE_EVENT:
// MessageBox(NULL,
// _T("Program being closed!"),_T("CEvent"),MB_OK);
break;
case CTRL_LOGOFF_EVENT:
// MessageBox(NULL,
// _T("User is logging off!"),_T("CEvent"),MB_OK);
break;
case CTRL_SHUTDOWN_EVENT:
// MessageBox(NULL,
// _T("User is logging off!"),_T("CEvent"),MB_OK);
break;
}
return TRUE;
}
#endif