Working on regex and validator
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
Compiler: g++
|
Compiler: g++
|
||||||
Flags: -static-libgcc -static-libstdc++ -lws2_32
|
Flags: -std=c++11 -static-libgcc -static-libstdc++ -lws2_32
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
Do not send auto reply
|
Fix regex validation, should be 16 character hexadecimal starting with e004
|
||||||
|
Fix validation for file checker file
|
||||||
Change card0.txt file based on information given by client
|
Change card0.txt file based on information given by client
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -13,6 +13,7 @@ Change card0.txt file based on information given by client
|
|||||||
#include "argh.h"
|
#include "argh.h"
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#pragma comment(lib,"ws2_32.lib") //Winsock Library
|
#pragma comment(lib,"ws2_32.lib") //Winsock Library
|
||||||
|
|
||||||
@@ -229,6 +230,31 @@ int main (int argc, char* argv[])
|
|||||||
//add null character, if you want to use with printf/puts or other string handling functions
|
//add null character, if you want to use with printf/puts or other string handling functions
|
||||||
buffer[valread] = '\0';
|
buffer[valread] = '\0';
|
||||||
printf("%s:%d - %s \n" , inet_ntoa(address.sin_addr) , ntohs(address.sin_port), buffer);
|
printf("%s:%d - %s \n" , inet_ntoa(address.sin_addr) , ntohs(address.sin_port), buffer);
|
||||||
|
|
||||||
|
// the 'buffer' is the string to use to edit our card0.txt file
|
||||||
|
|
||||||
|
// check if the check file exists
|
||||||
|
//if(std::ifstream(check))
|
||||||
|
//{
|
||||||
|
// check file exists, rewrite
|
||||||
|
// regex to validate buffer is a e004 hex number
|
||||||
|
std::regex cardRegex("[eE]004[0-9a-fA-F]{12}");
|
||||||
|
if(std::regex_match(buffer, cardRegex))
|
||||||
|
{
|
||||||
|
std::cout << "Data recieved is a valid game card" << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Data recieved is not a valid game card" << std::endl;
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// no check file
|
||||||
|
// std::cout << "No check file! Will not re-write: " << file << std::endl;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
send( s , buffer , valread , 0 );
|
send( s , buffer , valread , 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user