Repository navigation
Expand file tree
/
Copy pathServer.h
More file actions
56 lines (44 loc) · 1.35 KB
/
Copy pathServer.h
File metadata and controls
56 lines (44 loc) · 1.35 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
#pragma once
#include <cstdio>
#include <cstdint>
#include <winsock2.h>
#pragma comment(lib, "Ws2_32.lib")
#include "stdint.h"
#include "stdio.h"
#include <cstdlib>
#include <unordered_map>
#include <string>
#include <sstream>
#include <fstream>
#include <thread>
enum class KReturn;
class Server
{
public:
KReturn Init(uint16_t Port, uint32_t ChatCap);
int send_all(SOCKET s, const char* msg, int len);
int send_packet(SOCKET s, const char* msg);
int revc_exact(SOCKET s, char* incomingMsg, int len);
int recv_packet(SOCKET s, char incomingMsg[256]);
KReturn server_commands(SOCKET s, const char* buffer);
bool LoggedIn(SOCKET s);
KReturn ServerMessage(SOCKET s, std::string text);
void BroadCastPublic(SOCKET s, std::string& text);
void logPublic(const std::string& line);
void StartBroadCast(uint16_t port, uint32_t intervalseconds);
void BroadCastLoop(uint32_t intervalSeconds);
std::string BuildBroadcastMessage() const;
void StopBroadCast();
private:
std::unordered_map<SOCKET, std::string> SocketToUser;
std::unordered_map<std::string, SOCKET> UserToSocket;
std::ofstream PublicLog;
uint16_t AdvertisedServerPort = 0;
sockaddr_in BroadcastAddr{};
SOCKET UdpBroadcastSocket = INVALID_SOCKET;
std::thread UdpBroadcastThread;
std::atomic<bool> UdpBroadcastRunning = false;
fd_set MasterSet;
fd_set ReadySet;
int MaxSocketNum;
};