-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.cpp
More file actions
53 lines (48 loc) · 1.27 KB
/
client.cpp
File metadata and controls
53 lines (48 loc) · 1.27 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
#include <windows.h>
#include "text.h"
#include "operation.h"
#include "console.h"
#include "encryption.h"
#include "license.h"
#include "player.h"
#include "client.h"
// sends data to the client. really, it's just a wrapper for send()
int SendClient(CLIENT* c,void* data,int size)
{
int posn = 0;
int lastsend;
while (posn < size)
{
lastsend = send(c->socket,(char*)((DWORD)data + posn),size - posn,0);
if ((lastsend == SOCKET_ERROR) || (lastsend == 0)) return (-1);
posn += lastsend;
}
return 0;
}
// receives data from the client. really, it's just a wrapper for recv()
int ReceiveClient(CLIENT* c,void* data,int size)
{
int posn = 0;
int lastrecv;
while (posn < size)
{
lastrecv = recv(c->socket,(char*)((DWORD)data + posn),size - posn,0);
if (lastrecv == 0) return (-1);
if (lastrecv == SOCKET_ERROR)
{
if (WSAGetLastError() != WSAEWOULDBLOCK) return (-1);
else Sleep(0);
} else posn += lastrecv;
}
return 0;
}
// frees a client and associated memory
int DeleteClient(CLIENT* c)
{
operation_lock(c);
//if (c->playerInfo.account) free(c->playerInfo.account);
closesocket(c->socket);
CloseHandle(c->thread);
free(c);
return 0;
}