Codice:
#pragma comment(lib,"ws2_32.lib")
#include <WinSock2.h>
#include "TwojeImie.h"
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while(std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
return split(s, delim, elems);
}
std::string decrypt(std::string str,int size);
std::string EncryptLoginPacket(std::string str);
void main()
{
WSAData wsa;
WORD Version = MAKEWORD(2,1);
WSAStartup(Version, &wsa);
SOCKET Listen = socket(AF_INET, SOCK_STREAM, 0);
SOCKET Connect = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN Server;
char ip[14] = "5.211.100.16";
int port = 4003;
Server.sin_addr.s_addr = inet_addr(ip);
Server.sin_family = AF_INET;
Server.sin_port = htons(port);
bind(Listen, (SOCKADDR*)&Server, sizeof(Server));
listen(Listen, 1);
int size = sizeof(Server);
std::cout << "--------------------------------------------------------------------------------"
<< " Server connected." << std::endl
<< " Host: " << ip << " : " << port << std::endl
<< "--------------------------------------------------------------------------------" << std::endl;
MYSQL *nosdb;
if ((nosdb = mysql_init (NULL)) == NULL) {
cout << " CRITICAL ERROR: Can't start mysql" << endl;
getchar();
exit(1);
}else{
if(!mysql_real_connect(nosdb, "127.0.0.1" ,"root", "******" ,"privateserver", 3306, 0,0))
{cout << " CRITICAL ERROR: Can't connect to DB" << endl;
getchar();
exit(1);}
else
{cout << "Service MySQL Started" << endl;}
}
MYSQL_ROW mrow;
MYSQL_RES *mres;
for(;{
if(Connect = accept(Listen, (SOCKADDR*)&Server, &size)){
std::cout << "Connection accepted from: " << inet_ntoa(Server.sin_addr) << std::endl;
int sizes;
char recvbuf[512];
sizes = recv(Connect,recvbuf,512,0);
std::string Packet;
for(int i =0; i < sizes;i++){Packet += (int)recvbuf[i] - 0xf ^0xc3;}
std::cout << Packet << std::endl;
std::string fail = "NsTest 7998 5.211.100.16:1337:0:1.0.NosPrivateServer -1:-1:-1";
send(Connect,EncryptLoginPacket(fail).c_str(), EncryptLoginPacket(fail).length() +1,0);
}
}
WSACleanup();
std::cin.get();
std::string fail = "fail id or pw wrong";
send(Connect,fail.c_str(),fail.size(),0);
}
std::string decrypt(std::string str,int size)
{
std::string decrypted_string;
for (int i = 0; i < size; i++) { decrypted_string += str[i] - 0xF ^ 0xC3; }
return decrypted_string;
}
std::string EncryptLoginPacket(std::string str)
{
std::string encrypted_string;
for (int i = 0; i < str.length(); i++) { encrypted_string += str[i] + 0xF; }
return encrypted_string += 0x19;
}