1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
#include <fstream>
#include <winsock2.h>
#include <sstream>
#pragma comment(lib,"ws2_32.lib")
int main()
{
WSADATA WsaDat;
WSAStartup(MAKEWORD(2, 2),&WsaDat);
SOCKET Listen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN serverInf;
serverInf.sin_family = AF_INET;
serverInf.sin_addr.s_addr = INADDR_ANY;
serverInf.sin_port =htons(8089);
bind(Listen, (SOCKADDR*)(&serverInf), sizeof(serverInf));
listen(Listen, 1);
SOCKET TempSock = SOCKET_ERROR;
while (TempSock == SOCKET_ERROR)
{
std::cout << "Waiting for incoming connections...\r\n";
TempSock = accept(Listen, NULL, NULL);
}
Listen = TempSock;
std::cout << "Client connected! @\n" ;
char *Welcome = "Welcome to Operation!\n\r";
char *Introduction = "My name is K.L.I.B. How may I help ? \n\n\r"; //Kompletely Lifelike Intellegent Bot
send(Listen, Welcome, strlen(Welcome), 0);
send(Listen, Introduction, strlen(Introduction), 0);
char OrderRecv[100];
std::stringstream OrderTemp;
std::string Order;
do
{
memset(OrderRecv, 0, sizeof(OrderRecv));
recv(Listen, OrderRecv, sizeof(OrderRecv), 0);
OrderTemp << OrderRecv;
OrderTemp >> Order;
std::cout << OrderRecv;
if (Order == "Login")
{
std::cout << "Login attempt @" /*Insert IP here*/;
}
} while (true);
system("pause"); //Don't hate me, I am removing it as soon as I get this all sorted.
// Even though the while loop goes forever, I want to add a break command so this is it's
// fail safe so I can add code later
shutdown(Listen, SD_SEND);
closesocket(Listen);
WSACleanup();
}
|