Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/application.cc55
-rw-r--r--src/core/netconnection.cc4
-rw-r--r--src/core/netserver.cc9
3 files changed, 25 insertions, 43 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index 485bac2..4964e50 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -57,43 +57,6 @@ void func_disconnect(std::string const &args)
application()->disconnect();
}
-/*
-void func_name(std::string const &args) {
- std::istringstream argstream(args);
- std::string name;
- if (argstream >> name) {
- if (name.size() > 16)
- name = name.substr(0,16);
- } else {
- con_print << "name " << Player::local.name() << "\n";
- return;
- }
-
- if (name == Player::local.name()) {
- con_print << "name " << name << "\n";
- return;
- }
-
- if (application()->netserver) {
- std::ostringstream osstream;
- osstream << "msg info " << Player::local.name() << " renamed to " << name << "\n";
- application()->netserver->broadcast(osstream.str());
-
- con_print << "msg info " << Player::local.name() << " renamed to " << name << "\n";
- } else if (application()->netconnection.connected()) {
- std::ostringstream osstream;
- osstream << "name " << name << "\n";
- application()->netconnection.send(osstream.str());
-
- con_print << "name " << name << "\n";
- } else {
- con_print << "name " << name << "\n";
- }
-
- Player::local.player_name = name;
-}
-*/
-
// --------------- signal_handler -----------------------------------
extern "C" void signal_handler(int signum)
@@ -175,6 +138,15 @@ void Application::init()
Cvar::net_maxclients = Cvar::get("net_maxclients", "16", Cvar::Archive);
Cvar::net_timeout = Cvar::get("net_timeout", "20", Cvar::Archive);
+#ifdef _WIN32
+ // Initialize win32 socket library
+ WSADATA wsa_data;
+ WORD wsa_version = MAKEWORD(2, 0);
+ if (WSAStartup(wsa_version, wsa_data) != 0 ) {
+ con_warn << "Could not initialize scoket library!" << std::endl;
+ }
+#endif
+
// register our engine functions
Func::add("print", func_print);
Func::add("help", func_help);
@@ -182,8 +154,6 @@ void Application::init()
Func::add("connect", func_connect);
Func::add("disconnect", func_disconnect);
-
- //Func::add("name", func_name);
}
void Application::shutdown()
@@ -207,7 +177,11 @@ void Application::shutdown()
Func::remove("connect");
Func::remove("disconnect");
- //Func::remove("name");
+
+#ifdef _WIN32
+ // shutdown win32 socket library
+ WSACleanup();
+#endif
CommandBuffer::shutdown();
@@ -254,7 +228,6 @@ void Application::connect(std::string const &host)
void Application::disconnect()
{
-
if(application_game) {
delete application_game;
application_game = 0;
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 18ae3bc..9fd4e33 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -96,7 +96,11 @@ void NetConnection::disconnect()
transmit();
FD_ZERO(&clientset);
+#ifdef _WIN32
+ closesocket(connection_fd);
+#else
close(connection_fd);
+#endif
}
connection_fd = -1;
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index e3e01a3..8b9cbe5 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -116,8 +116,13 @@ NetServer::~NetServer()
}
clients.clear();
- if (valid())
- ::close(fd());
+ if (valid()) {
+#ifdef _WIN32
+ closesocket(fd());
+#else
+ close(fd());
+#endif
+ }
}
// remove disconnected clients