1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
28 #include "FieldImpls.h"
29 #include "GameVersion.h"
30 #include "SavableHeaders.h"
31 #include "TableImpls.h"
32 #include "DatabaseMgr.h"
34 #include "ListenSocket.h"
35 #include "SQLSocket.h"
36 #include "UBHandler.h"
38 #include "SqliteMgr.h"
43 printf("exiting...\n");
48 void add(SocketHandler
* h
,int port
)
50 ListenSocket
<UBSocket
> *l
= new ListenSocket
<UBSocket
>(*h
);
51 printf("Attempting bind on port %d... ", port
);
54 printf("Not successful\n");
59 l
-> SetDeleteByHandler();
63 void addSQL(SocketHandler
* h
, int port
)
65 ListenSocket
<SQLSocket
> *l
= new ListenSocket
<SQLSocket
>(*h
);
66 printf("Attempting SQL bind on port %d... ", port
);
69 printf("Not successful\n");
74 l
-> SetDeleteByHandler();
78 static void logToFile(const std::string
& text
)
80 std::string output
= text
;
83 std::ofstream errorfile
;
84 errorfile
.open("errorlog.txt", std::ios_base::app
);
86 if(!errorfile
.is_open())
88 printf("Could not open errorlog file.\n");
92 errorfile
.write(output
.c_str(), output
.size());
95 printf("Could not write to errorlog file.\n");
103 extern bool g_shutdown
;
104 extern bool g_nocatch
;
106 int main(int argc
, char** argv
)
110 if(!strncmp("-n", argv
[1], 2))
114 printf("Opening database...\n");
115 std::string dbname
= game::vname
;
116 dbname
.append(".db");
117 DatabaseMgr::Initialize(dbname
);
120 db::TableImpls::Get()->Initialize();
122 printf("Binding ports...\n");
124 add(UBHandler::Get(), 4000);
125 add(UBHandler::Get(), 4040);
126 add(UBHandler::Get(), 5060);
127 addSQL(UBHandler::Get(), 9090);
129 printf("Running!\n");
135 UBHandler::Get()->Select(0, 200000);
136 UBHandler::Get()->SwitchEditors();
141 UBHandler::Get()->Select(0, 200000);
142 UBHandler::Get()->SwitchEditors();
143 } catch(std::exception
& e
) {
144 printf("Cought exception '%s', trying to quit gracefully.\n", e
.what());
152 UBHandler::Get()->Shutdown();
153 UBHandler::Get()->Select();
154 } catch(std::exception
& e
) {
155 printf("Cought exception '%s' while closing sockets, trying to quit gracefully.\n", e
.what());
161 } catch(std::exception
& e
) {
162 printf("Cought exception '%s' while freeing the UBHandler, trying to quit gracefully.\n", e
.what());
169 mud::Managers::Free();
170 } catch(std::exception
& e
) {
171 printf("Cought exception '%s' while freeing mud::Managers, trying to quit gracefully.\n", e
.what());
177 } catch(std::exception
& e
) {
178 printf("Cought exception '%s' while freeing the SqliteMgr, trying to quit gracefully.\n", e
.what());
184 } catch(std::exception
& e
) {
185 printf("Cought exception '%s' while freeing the DatabaseMgr, trying to quit gracefully.\n", e
.what());
189 printf("End of program.\n");