Skip to content

Commit

Permalink
Added client.cpp. Contains its own main method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehv11001 committed Apr 25, 2017
1 parent 901501b commit 35126f4
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/Client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma comment(lib, "ws2_32.lib")
#include <WinSock2.h>
#include <iostream>
#include <string>

int main()
{
//Winsock startup
char User[5] = "14\r\n";
char Password[9] = "306173\r\n";
char Opponent[5] = "0\r\n";

WSAData wsaData;
WORD DllVersion = MAKEWORD(2, 1);
if (WSAStartup(DllVersion, &wsaData) != 0)
{
MessageBoxA(NULL, "Winsock startup failed", "Error", MB_OK | MB_ICONERROR);
}

SOCKADDR_IN addr;
int sizeofaddr = sizeof(addr);
addr.sin_addr.s_addr = inet_addr("137.99.15.69");
addr.sin_port = htons(3499);
addr.sin_family = AF_INET; //IPv4 socket

SOCKET Connection = socket(AF_INET, SOCK_STREAM, NULL);
if (connect(Connection, (SOCKADDR*)&addr, sizeofaddr) != 0)
{
MessageBoxA(NULL, "Failed to Connect", "Error", MB_OK | MB_ICONERROR);
return 0;
}
std::cout << "Connected!" << std::endl;
char Terminate[4] = "\r\n";

char Message[64];
recv(Connection, Message, sizeof(Message), NULL); //Receive SAM, Username
std::cout << "read: " << Message << std::endl; //Send Username
recv(Connection, Message, sizeof(Message), NULL);

std::cout << "read: " << Message << std::endl;
send(Connection, User, sizeof(User), MSG_OOB);
std::cout << "sent: " << User << std::endl;

recv(Connection, Message, sizeof(Message), NULL); //Receive and send Password
std::cout << "read: " << Message << std::endl;
send(Connection, Password, sizeof(Password), MSG_OOB);

recv(Connection, Message, sizeof(Message), NULL); //Receive and send opponent
std::cout << "read: " << Message << std::endl;
send(Connection, Opponent, sizeof(Opponent), NULL);
std::cout << "sent: " << Opponent << std::endl;
recv(Connection, Message, sizeof(Message), NULL); //Receive game ID
std::cout << "read: " << Message << std::endl;
std::string GameID = Message; //get Game ID
GameID = GameID.substr(5, 10);

recv(Connection, Message, sizeof(Message), NULL); //Receive color
std::string Color = Message; //Get Color
Color = Color.substr(5, 6); //For some reason I can't get just 'White' or just 'Black', ':White' is closest I can get
std::cout << Color << std::endl;
std::cout << "I am playing as " << Color << " in game number " << GameID << std::endl;
std::cout << "read: " << Message << std::endl;

if (Color == ":White")
{
std::cout << "WHITE" << std::endl;
while (TRUE)
{

}
}
else
{
std::cout << "BLACK" << std::endl;
while (TRUE)
{

}
}

system("pause");
return 0;
}

0 comments on commit 35126f4

Please sign in to comment.