-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added client.cpp. Contains its own main method.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |