-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.cpp
More file actions
44 lines (40 loc) · 1.04 KB
/
Console.cpp
File metadata and controls
44 lines (40 loc) · 1.04 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
#include "Console.h"
#include <sstream>
bool Spyder::Console::Connect(const std::string &strIP, unsigned short usPort)
{
m_socket = socket(AF_INET, SOCK_DGRAM, 0);
if(m_socket == -1)
{
return false;
}
memset((void*)&m_serverAddr, 0, sizeof(m_serverAddr));
m_serverAddr.sin_len = sizeof(sockaddr_in);
m_serverAddr.sin_family = AF_INET;
m_serverAddr.sin_port = usPort;
m_serverAddr.sin_addr.s_addr = inet_addr(const_cast<char*>(strIP.c_str()));// I'm so sorry for this
return true;
}
bool Spyder::Console::SendPacket(const std::string &strSubsystem, Packet& packet)
{
std::stringstream ss;
int length = strSubsystem.length();
ss << std::string((char*)&length, 4);
ss << strSubsystem;
ss << packet.GetData();
if(sendto(m_socket, const_cast<char*>(ss.str().c_str()), ss.str().length(), 0, (sockaddr*)&m_serverAddr, m_serverAddr.sin_len) == -1)
{
return false;
}
return true;
}
Spyder::Console* Spyder::Console::GetSingleton()
{
static Spyder::Console *c = new Console;
return c;
}
Spyder::Console::Console()
{
}
Spyder::Console::~Console()
{
}