diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-02 17:38:28 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-02 17:38:28 +0200 |
commit | e1c83be32d5435d3c2bbc1468b24ba8c0728bac3 (patch) | |
tree | de85217613aa2e95eceadc6452602bf93e07f96b /ProtoProxy/Server.cpp | |
parent | ToLua does not like the override keyword :( (diff) | |
download | cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.tar cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.tar.gz cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.tar.bz2 cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.tar.lz cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.tar.xz cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.tar.zst cuberite-e1c83be32d5435d3c2bbc1468b24ba8c0728bac3.zip |
Diffstat (limited to 'ProtoProxy/Server.cpp')
-rw-r--r-- | ProtoProxy/Server.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/ProtoProxy/Server.cpp b/ProtoProxy/Server.cpp new file mode 100644 index 000000000..e0abcb596 --- /dev/null +++ b/ProtoProxy/Server.cpp @@ -0,0 +1,75 @@ +
+// Server.cpp
+
+// Interfaces to the cServer class encapsulating the entire "server"
+
+#include "Globals.h"
+#include "Server.h"
+#include "Connection.h"
+
+
+
+
+
+cServer::cServer(void)
+{
+}
+
+
+
+
+
+int cServer::Init(short a_ListenPort, short a_ConnectPort)
+{
+ m_ConnectPort = a_ConnectPort;
+ WSAData wsa;
+ int res = WSAStartup(0x0202, &wsa);
+ if (res != 0)
+ {
+ printf("Cannot initialize WinSock: %d\n", res);
+ return res;
+ }
+
+ printf("Generating protocol encryption keypair...\n");
+ AutoSeededRandomPool rng;
+ m_PrivateKey.GenerateRandomWithKeySize(rng, 1024);
+ RSA::PublicKey pk(m_PrivateKey);
+ m_PublicKey = pk;
+
+ m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ sockaddr_in local;
+ memset(&local, 0, sizeof(local));
+ local.sin_family = AF_INET;
+ local.sin_addr.s_addr = htonl(0x7f000001); // localhost
+ local.sin_port = htons(a_ListenPort);
+ bind(m_ListenSocket, (sockaddr *)&local, sizeof(local));
+ listen(m_ListenSocket, 1);
+ return 0;
+}
+
+
+
+
+
+void cServer::Run(void)
+{
+ printf("Server running\n");
+ while (true)
+ {
+ sockaddr_in Addr;
+ ZeroMemory(&Addr, sizeof(Addr));
+ int AddrSize = sizeof(Addr);
+ SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize);
+ if (client == INVALID_SOCKET)
+ {
+ printf("accept returned an error: %d; bailing out", WSAGetLastError());
+ return;
+ }
+ cConnection Connection(client, *this);
+ Connection.Run();
+ }
+}
+
+
+
+
|