-
Notifications
You must be signed in to change notification settings - Fork 0
/
Header.h
82 lines (73 loc) · 1.57 KB
/
Header.h
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
#pragma once
#include "stdafx.h"
#ifndef MYHEADER
#define MYHEADER
#define PORT 5000
#define LISTENADDRESS "127.0.0.1"
#define PACKETSIZE 500
enum Event {
RECVD = 0,
SENDD = 1,
NUMOFEVENTNUMBERS = 2
};
template<typename tEntity>
class Delegate {
typedef void* InstancePtr;
typedef void(*InternalFnc)(InstancePtr, tEntity*);
InstancePtr iPtr;
InternalFnc iFnc;
public:
template<class C, void(C::*Function)(tEntity*)>
static Delegate* create(C* obj) {
Delegate *del = new Delegate();
del->Bind<C, Function>(obj);
return del;
}
template<class C, void(C::*Function)(tEntity*)>
void Bind(C* obj) {
iPtr = obj;
iFnc = &classMethod<C, Function>;
}
template<class C, void(C::*FUnction)(tEntity*)>
static void classMethod(InstancePtr *o, tEntity* s) {
return (static_cast<C*>(o)->iFnc)(s);
}
void Invoke(tEntity* s) {
iFnc(iPtr, s);
}
};
class OverlappedStruct {
public:
OVERLAPPED m_ov;
Event ev;
bool m_Inuse;
OverlappedStruct() {
memset(&m_ov, 0, sizeof(m_ov));
m_Inuse = false;
}
OverlappedStruct(Event e):ev(e) {
memset(&m_ov, 0, sizeof(m_ov));
}
void Reset(Event e) {
memset(&m_ov, 0, sizeof(m_ov));
ev = e;
}
Event getEvent()const { return ev; }
};
enum PacketType {
NICK = 3,
TOALL = 4,
PM = 5,
CLIST=6
};
struct Packet {
unsigned int pkType = 0;
char data[PACKETSIZE]="\0";
void setPacket(char *buffer) {
memcpy(buffer, this, sizeof(Packet));// pushing data after type
}
void undoPacket(char* buffer) {
memcpy(this, buffer, sizeof(Packet));
}
};
#endif