Started checker file work
This commit is contained in:
@@ -4,11 +4,13 @@ Flags: -std=c++11 -static-libgcc -static-libstdc++ -lws2_32
|
||||
Run ex: cardnet.exe -c1="G:\card0.txt" -c2="H:\card0.txt" -l1="G:\check.txt" -l2="H:\check.txt" -p="4500"
|
||||
|
||||
TODO:
|
||||
Fix extra buffer character (maybe, it occurs in telnet)
|
||||
Fix validation for file checker file
|
||||
Change card0.txt file based on information given by client (p1/p2)
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "argh.h"
|
||||
#include <winsock2.h>
|
||||
@@ -18,10 +20,11 @@ Change card0.txt file based on information given by client (p1/p2)
|
||||
#pragma comment(lib,"ws2_32.lib") //Winsock Library
|
||||
|
||||
void exampleMessage();
|
||||
bool checkExist(std::string);
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
std::string card_p1, card_p2, check_p1, check_p2; // file = card0.txt ; check = check.txt
|
||||
std::string card_p1, card_p2, check_p1, check_p2; // card = card0.txt ; check = check.txt
|
||||
int port = 0; // port number to listen
|
||||
|
||||
argh::parser cmdl; // command line parser
|
||||
@@ -56,8 +59,6 @@ int main (int argc, char* argv[])
|
||||
try
|
||||
{
|
||||
port = stoi(param.second); // convert to int
|
||||
if (port < 1 || port > 65535) // validate port number
|
||||
exampleMessage();
|
||||
}
|
||||
catch (std::invalid_argument) // failed convert
|
||||
{
|
||||
@@ -66,7 +67,7 @@ int main (int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if(card_p1 == "" || check_p1 == "" || port == 0) // failed validation
|
||||
if(card_p1 == "" || check_p1 == "" || port < 1 || port > 65535) // failed validation
|
||||
exampleMessage();
|
||||
|
||||
std::cout << "Card P1:\t" << card_p1 << std::endl;
|
||||
@@ -245,8 +246,13 @@ int main (int argc, char* argv[])
|
||||
if(std::regex_match(buffer, cardRegex))
|
||||
{
|
||||
|
||||
printf("Recieved by: %s:%d contains: %s \n" , inet_ntoa(address.sin_addr) , ntohs(address.sin_port), buffer);
|
||||
printf("\nRecieved by: %s:%d contains: %s \n" , inet_ntoa(address.sin_addr) , ntohs(address.sin_port), buffer);
|
||||
std::cout << "Data recieved is a valid game card" << std::endl;
|
||||
|
||||
// validate if buffer string is for p1 or p2
|
||||
|
||||
// check for the checker file apporiately
|
||||
std::cout << "Looking for check file in: "<< check_p1 << "... "<< (checkExist(check_p1) ? "Found" : "Not found") << std::endl; //test
|
||||
}
|
||||
else // don't do anything if not valid
|
||||
{
|
||||
@@ -289,5 +295,10 @@ void exampleMessage() // help menu
|
||||
std::cout << std::endl << "Ex (1P): cardnet.exe -c1=\"G:\\card0.txt\" -l1=\"G:\\check.txt\" -p=\"4500\"" << std::endl;
|
||||
std::cout << "Ex (2P): cardnet.exe -c1=\"G:\\card0.txt\" -c2=\"H:\\card0.txt\" -l1=\"G:\\check.txt\" -l2=\"H:\\check.txt\" -p=\"4500\"" << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
bool checkExist (std::string fileName)
|
||||
{
|
||||
std::ifstream infile(fileName);
|
||||
return infile.good();
|
||||
}
|
Binary file not shown.
Reference in New Issue
Block a user