Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: MSBuild

on: [push]

env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: .

# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m ${{env.SOLUTION_FILE_PATH}}
2 changes: 2 additions & 0 deletions RoboCat/Chapter3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Inc\PlayerUser.h" />
<ClInclude Include="Inc\SocketAddress.h" />
<ClInclude Include="Inc\SocketAddressFactory.h" />
<ClInclude Include="Inc\SocketUtil.h" />
Expand All @@ -379,6 +380,7 @@
<ClInclude Include="Inc\RoboCatShared.h" />
<ClInclude Include="Inc\UDPSocket.h" />
<ClCompile Include="Src\Main.cpp" />
<ClCompile Include="Src\PlayerUser.cpp" />
<ClCompile Include="Src\SocketAddress.cpp" />
<ClCompile Include="Src\SocketAddressFactory.cpp" />
<ClCompile Include="Src\SocketUtil.cpp" />
Expand Down
38 changes: 38 additions & 0 deletions RoboCat/Inc/PlayerUser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include <thread>
#include "RoboCatPCH.h"

struct PlayerUser
{
int playerNumber;
std::string playerName;
std::string SEPERATOR_TOKEN = "!";
int sendRecvFlag = -1;
bool quit;
float delayTimer = 0;
std::thread chatThread;

std::string CLIENT_SEND_PORT = "1250", CLIENT_RECV_PORT = "2250";

TCPSocketPtr sendSocket, recvSocket, recvConnSocket;

public:
PlayerUser();
PlayerUser(int _pnum, std::string username);
~PlayerUser();

std::string getUsername() { return playerName; };

void startTcpThread(bool isServer);

void initTcpClient(std::string sendPort, std::string recvPort);
void initTcpServer(std::string listenPort);

std::string messageIntoString(std::string _message);
void decodeMessageString(std::string _messageString);
void sendMessage(std::string _message);

void closeSockets();
void shutdown();

};
2 changes: 1 addition & 1 deletion RoboCat/Inc/RoboCatPCH.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#pragma once

#include <RoboCatShared.h>

Expand Down
1 change: 1 addition & 0 deletions RoboCat/Inc/SocketAddress.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
class SocketAddress
{
public:
Expand Down
1 change: 1 addition & 0 deletions RoboCat/Inc/SocketUtil.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
enum class SocketAddressFamily
{
INET = AF_INET,
Expand Down
1 change: 1 addition & 0 deletions RoboCat/Inc/StringUtils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
namespace StringUtils
{
string GetCommandLineArg( int inIndex );
Expand Down
1 change: 1 addition & 0 deletions RoboCat/Inc/TCPSocket.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
class TCPSocket
{
public:
Expand Down
2 changes: 1 addition & 1 deletion RoboCat/Inc/UDPSocket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#pragma once

class UDPSocket
{
Expand Down
48 changes: 47 additions & 1 deletion RoboCat/Src/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

#include "RoboCatPCH.h"
#include <thread>
#include <iostream>
#include "PlayerUser.h"


PlayerUser* user;
bool isRunning = true;
//std::thread t;


#if _WIN32
int main(int argc, const char** argv)
Expand All @@ -17,6 +25,44 @@ int main(int argc, const char** argv)

SocketUtil::StaticInit();

std::string username = "charles entertainment cheese";

// Server Code --------------
bool isServer = StringUtils::GetCommandLineArg(1) == "server";
if (isServer)
{
username = "server";
user = new PlayerUser(2, username);
user->startTcpThread(isServer);
}

// Client Code --------------
if (!isServer)
{
std::cout << "Enter username please:\n";
std::getline(std::cin, username);
user = new PlayerUser(1, username);
user->startTcpThread(isServer);
}

std::cout << "Welcome, " + username + "!\nEnter !quit to exit.\n";
std::cout << "< " + user->getUsername() + " >: ";
while (isRunning)
{
std::string input;

std::getline(std::cin, input);

std::cout << "< " + user->getUsername() + " >: ";
std::cout << input << "\n";
if (input == "!quit" || input == "!Quit" || input == "!QUIT")
isRunning = false;
else
user->sendMessage(input);
}

delete user;

SocketUtil::CleanUp();

return 0;
Expand Down
Loading