Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
513229e
Create main
BrynjarSt Oct 19, 2017
8f21f61
Update main
BrynjarSt Oct 19, 2017
8f0c1d7
Delete main
BrynjarSt Oct 19, 2017
a2d3cc3
I changed thisi
Oct 19, 2017
b602c5d
I change this
Oct 19, 2017
faa9c0f
I have delted main
Oct 19, 2017
665e1b9
I have made this file
Oct 19, 2017
bd45713
Delted againi
Oct 19, 2017
93fc1c3
THIS IS A DEEZ NUTS TEST
supersylle14 Oct 19, 2017
6752e96
Merge branch 'master' of https://github.com/CamillaKirstineMarkmann/P…
supersylle14 Oct 19, 2017
1680d36
HEY I DELETED DEEZ NUTS
supersylle14 Oct 19, 2017
51ca11b
Added servers files to project main branch
Oct 19, 2017
c65eaca
I have fucked this up
CamillaKirstineMarkmann Oct 23, 2017
520bd62
Fuck off
CamillaKirstineMarkmann Oct 23, 2017
9c3bd5f
This is the real deali
Oct 23, 2017
531cba5
I changed thisi
Oct 23, 2017
a9a4af9
This is the beginning
Oct 23, 2017
43f83c4
Fixed it
Oct 23, 2017
66337da
Fixed it
Oct 23, 2017
b70227f
Delted stuff.
Oct 23, 2017
60a1f3c
Hello here i am
Oct 23, 2017
b2a93d9
See i am Camilla and i did this
Oct 23, 2017
0e3342b
Andreas er en kæmpe idiot
CamillaKirstineMarkmann Oct 23, 2017
a54c268
Lobby was created
CamillaKirstineMarkmann Oct 23, 2017
92275ad
Lobby was created
CamillaKirstineMarkmann Oct 23, 2017
aa26759
Made a lot of changes to the structure and set up functions ready to be
Oct 24, 2017
2d9b5fd
hej
supersylle14 Oct 25, 2017
bc157f7
Merge branch 'SylvesterBranch'
supersylle14 Oct 25, 2017
96cf0a3
I did this
Oct 25, 2017
600c938
ok
Oct 25, 2017
27ee676
Minor changes
Oct 25, 2017
8ac8a59
Now it works again Andreas
CamillaKirstineMarkmann Oct 25, 2017
b40b756
...
CamillaKirstineMarkmann Oct 25, 2017
c90d9c0
Menu is now a function
CamillaKirstineMarkmann Oct 25, 2017
6e12986
Choose weapon menu created
CamillaKirstineMarkmann Oct 26, 2017
234bfb6
Removed Slyvester Branch and created note with Main Branch
Oct 26, 2017
9b8e198
Hola
CamillaKirstineMarkmann Oct 26, 2017
87104b2
Merge branch 'master' of https://github.com/CamillaKirstineMarkmann/P…
CamillaKirstineMarkmann Oct 26, 2017
bdb840d
made gitignore
Oct 26, 2017
8bcbe12
.
CamillaKirstineMarkmann Oct 26, 2017
8fac795
.
supersylle14 Oct 26, 2017
1e4d261
30-10-2017
supersylle14 Oct 30, 2017
d2b63f0
made weapon eval
amalierose Oct 30, 2017
31b03c1
Almost works
benjaminvinje Oct 30, 2017
4d88175
m
benjaminvinje Oct 30, 2017
32a52b0
Changed a lot
Oct 31, 2017
5780e6c
Fixed error
Nov 1, 2017
9cd1652
Added old functionality into new networking system
Nov 1, 2017
3749134
Added old functionality
Nov 1, 2017
cc68c5d
Final Checkup before merge
Nov 2, 2017
ef8419c
Cleaning the client site
CamillaKirstineMarkmann Nov 2, 2017
dba9135
Made a lot of changes
Nov 2, 2017
88ba583
Some shit
CamillaKirstineMarkmann Nov 2, 2017
cb35e00
Last change
Nov 2, 2017
8cbe6ad
Merge branch 'Client'
CamillaKirstineMarkmann Nov 2, 2017
c239c2f
Merge branch 'master' of https://github.com/CamillaKirstineMarkmann/P…
CamillaKirstineMarkmann Nov 2, 2017
5e019d7
Made some changes
Nov 2, 2017
6ff8a70
Last things
Nov 2, 2017
e5f5d1b
Finishing up
Nov 4, 2017
bb12aa8
Added 4 client support
Nov 5, 2017
64852d3
Done for now..
Nov 5, 2017
75b798f
Documentation added
Nov 5, 2017
ccaee02
Added Release
Nov 6, 2017
d491dd1
Added UML diagram
Nov 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Debug
218 changes: 218 additions & 0 deletions CLIENT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
//TCP CLIENT source file
#include "CLIENT.h"
using namespace std;

//Variables declared at the top in catagories:

//NETWORKING VARIABLES:
long SUCCESSFUL; //Contains the information we gain from sending and receiving data
WSAData WinSockData; //The WSAData object is only used once, when we call the WSAStartup function, it tells the computer to start using sockets
WORD DLLVersion; //Word are objects of a data size that our processor naturally handles (16 or 32-bit)
string CONVERTER; // in C++ you have to do a lot of convertions with strings because some functions can only handle certain types of strings
SOCKADDR_IN ADDRESS; //This object contains information about the socket, for example and ipadress or a port number
SOCKET sock; //This is the socket we use on this side... There is one at each side client and server, this side is called sock
char MESSAGE[200]; // this is a simpler string (a collection of characters). //Must be large enough to accomedate the largest amount of data sent from the server
char MessageFromServer01[800];
char MessageFromServer02[200];
char MessageFromServer03[200];
//Pre lobby user interaction
string RESPONSE; // These a instances of the type string

char WEAPONCHOICE;
string rockChosen;
string paperChosen;
string scissorChosen;


//Strings to know if game was already created
std::string GamewasCreatedonServer("Game created on server");
std::string Client01connect("You are connected as client 01\n");

std::string assignTaskServer;
std::string MESSAGEFROMSERVER;

//LOBBY VARRIABLES
int LOBBYCHOICE;
bool valid; //to make switch case run again
bool gameisCreated=false;

//Functions declared here before main
void createGame(){


//if()
strcpy_s(MESSAGE, "Server Create me a Game");
SUCCESSFUL = send(sock, MESSAGE, sizeof(MESSAGE), NULL);
gameisCreated = true;


SUCCESSFUL = recv(sock, MessageFromServer01, sizeof(MessageFromServer01), NULL); //Receives Client #
cout << MessageFromServer01 << endl;
//GamewasCreatedonServer = MessageFromServer01;
assignTaskServer = MessageFromServer01;
if (assignTaskServer.compare(Client01connect) == 0) {
cout << "Game was created" << endl;
} else
cout << "Game must be created by client 01!, Joining instead..." << endl;



}

void weaponChoice() { //Menu to choose weapon
cout << "Please choose your weapon!" << endl;

do { //do while loop to make switch case run again if choice is not valid
cout << "\n\nYou choose by pressing a character, followed by ENTER:\n\nR: Rock\nP: Paper\nS: Scissor\n...";

cin >> WEAPONCHOICE; //Get input from user about what they want to do

switch (WEAPONCHOICE) {
case 'r':
case 'R':
cout << "You chose rock"<< endl;
strcpy_s(MESSAGE, "You chose rock");
SUCCESSFUL = send(sock, MESSAGE, sizeof(MESSAGE), NULL);

SUCCESSFUL = recv(sock, MESSAGE, sizeof(MESSAGE), NULL);
CONVERTER = MESSAGE;
cout << CONVERTER;

valid = false;
break;
case 'p':
case 'P':
cout << "You chose paper"<< endl;
strcpy_s(MESSAGE, "You chose paper");
SUCCESSFUL = send(sock, MESSAGE, sizeof(MESSAGE), NULL);

SUCCESSFUL = recv(sock, MESSAGE, sizeof(MESSAGE), NULL);
CONVERTER = MESSAGE;
cout << CONVERTER;

valid = false;
break;
case 's':
case 'S':
cout << "You chose scissor"<< endl;
strcpy_s(MESSAGE, "You chose scissor");
SUCCESSFUL = send(sock, MESSAGE, sizeof(MESSAGE), NULL);

SUCCESSFUL = recv(sock, MESSAGE, sizeof(MESSAGE), NULL); //WE assign the received data into the variable Successfull. In this case the server sends us information if it is connected correctly. First parameter is the server socket, second is the data (A char array), third is the size of the data send and last is a flag a way you send this data, usually set to 0.
CONVERTER = MESSAGE; //The overloaded assignment operator allows us to convert Message (the simple string) into CONVERTER a more complex string.
cout << CONVERTER;

valid = false;
break;
default:
cout << "Please choose 'R', 'P' or 'S'";
valid = true;
break;
}
} while (valid);
}

void joinGame() {





if (gameisCreated==true) {
strcpy_s(MESSAGE, "Server join a game");
SUCCESSFUL = send(sock, MESSAGE, sizeof(MESSAGE), NULL);
SUCCESSFUL = recv(sock, MESSAGE, sizeof(MESSAGE), NULL);

cout << "You have joined a game" << endl;
weaponChoice();
}
/*else if(gameisCreated==false) {
cout << "No game has been created yet - a game will now be created for you" << endl;
createGame();
strcpy_s(MESSAGE, "Server join a game");
SUCCESSFUL = send(sock, MESSAGE, sizeof(MESSAGE), NULL);
weaponChoice();
} */
}


void menu() { //The Lobby
//while (true) {

cout << "\n\tCLIENT:\n\nHello, welcome to ROCK-PAPER-SCISSOR.";



do { //do while loop to make switch case run again if choice is not valid



cout << "\n\nThis is the lobby. Choose what you want to do(You choose by pressing a number, followed by ENTER):\n\n1: Create new game(Only First Client)\n2: Join game\n3: Leave game\n...";

cin >> LOBBYCHOICE; //Get input from user about what they want to do

switch (LOBBYCHOICE) {
case 1:
createGame();
weaponChoice();
valid = false;
break;
case 2:
/*
joinGame(); //Same as choice 1 for now
*/
createGame();
weaponChoice();
valid = false;
break;
case 3:
cout << "Goodbye";
valid = false;
break;
default:
cout << "That not a valid answer";
valid = true;
break;
}
} while (valid);
//}

}

void main(){
//These Parameters must be set before we can start the program, so they are run first:
DLLVersion = MAKEWORD(2, 2); //Sets the version of the winsock that we want to use, here it is 2, the second parameter is the location the parameter was created
SUCCESSFUL = WSAStartup(DLLVersion, &WinSockData); //WSAStartup tells the computer that we are going to use sockets
sock = socket(AF_INET, SOCK_STREAM, NULL); // Here we initialize the socket. First = to assign the socket to the varible sock. First Parameter= = AF_INET which is: the adress family specification, usually you use AF_INET for IPV4 format(type of IP), if you use IPv6 it is AF_INET6. Second parameter is the SOCK_STREAM(TCP Connection) There are many types for example SOCK_DGRAM, which dosent open connection between computers but sends data immediately (Called UDP). The last parameter is 0, and this is ''The possible options for the protocol parameter are specific to the address family and socket type specified.''
ADDRESS.sin_addr.s_addr = inet_addr("127.0.0.1"); //Local IP, the IP adress need to be converted into a format that can be used in Networking
ADDRESS.sin_family = AF_INET; // Tells the computer to use IP format IPv4 (Standard at the momemnt)
ADDRESS.sin_port = htons(54000); // Have to use htons method to convert it to network style, and then specify port number 444 which is the port we use.

//Once we have set up some basic networking stuff we ask the USER:
cout << "\n\tCLIENT: Do you want to connect to this server? Press 'y' for yes or 'n' for no.";
cin >> RESPONSE; //Inputs their response into the string variable RESPONSE
RESPONSE[0] = tolower(RESPONSE[0]); // Convert first letter to lower case and only this so if you type YES it takes Y = y

//Depending on the answer we have two options:
if (RESPONSE == "n"){ //if no then just quit
cout << "\n\tOK. Quitting instead.";
exit(0);
}

else if (RESPONSE == "y"){
connect(sock, (SOCKADDR*)&ADDRESS, sizeof(ADDRESS)); //This line connects us to the server. First parameter is our server socket, 2. parameter is the address information, 3. is the size of the 2. parameter.
SUCCESSFUL = recv(sock, MESSAGE, sizeof(MESSAGE), NULL); //WE assign the received data into the variable Successfull. In this case the server sends us information if it is connected correctly. First parameter is the server socket, second is the data (A char array), third is the size of the data send and last is a flag a way you send this data, usually set to 0.
CONVERTER = MESSAGE; //The overloaded assignment operator allows us to convert Message (the simple string) into CONVERTER a more complex string.
cout << ' ' << CONVERTER;
menu();
}

SUCCESSFUL = recv(sock, MESSAGE, sizeof(MessageFromServer01), NULL);

cout << MESSAGE << endl;


cout << "\n\n\t";
system("PAUSE");
exit(1);
}
15 changes: 15 additions & 0 deletions CLIENT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//TCP CLIENT header file

//Must include "Ws2_32.lib".
#pragma once //run once..
#pragma comment(lib,"Ws2_32.lib") //Winsock 2 lib.
#define _WINSOCK_DEPRECATED_NO_WARNINGS //Some of the winsock functions are outdate :(

//Standard HEADER files
#include <sdkddkver.h> //Google it
#include <WinSock2.h> //Standard winsock lib
#include<Windows.h> //Windows funciton
#include<iostream>
#include <string> //To use string functions
#include <cstdlib> //To use exit(0) call.
#define SCK_VERSION2 0x0202
Loading