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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
sf::VideoMode vmode (400,300,32);
sf::RenderWindow window (vmode,"Revenge Bot GUI");
sf::Text rect1text,rect2text,rect3text,rect4text;
sf::IpAddress address;
sf::TcpSocket ircsocket;
//some unimportant bits are left out
sf::Mutex mymutex;
//function headers
//function headers
int main()
{
//creating threads for send and recieve socket functions
sf::Thread recievethread (&recievestuff);
sf::Thread sendthread (&sendstuff,sendstring);
loadfiles();
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
{
window.close();
break;
}
case sf::Event::MouseButtonPressed:
{
//if within bounds of a rect then rect logic for that rect
}
case sf::Event::TextEntered:
{
//if key was pressed, string data goes to correct string and box
//case 4 is example
case 4:
{
saythis += (char)event.text.unicode;
if(((char)event.text.unicode==8&&(saythis.size()>1)))
{
int str_len = saythis.size();
saythis.erase(str_len-2,str_len);
}
rect4text.setString(saythis);
rect4text.setFont(Font_hammamam);
rect4text.setCharacterSize(28U);
rect4text.setPosition(sf::Vector2f(11,155));
rect4text.setColor(sf::Color::Black);
break;
}
default:
break;
}
}
default:
break;
}
}
//if conditions are met for log in, connect on click
if((dont_connect!=true)&&(ipstring!="")&&(port!="")&&(connected==false))
{
status = "Connect?";
status_code = 3;
if(rect_number==5)
{
login(ipstring,port);
}
}
printgui(output,output_count);
//must draw text and stuff on top of gui, else we won't see it
statusbox(status_code,status);
window.display();
std::cin>>sendstring;
if(!threads_have_launched)
{
sendthread.launch();
recievethread.launch();
threads_have_launched = true;
}
}
}
void recievestuff()
{
sf::Lock mylock(mymutex);
if(!ircsocket.receive(buffer2,sizeof(buffer2),recieved))
{
status = "recieve error!";
std::cout<<sock_status;
}
std::cout<<buffer2;
}
void sendstuff(std::string sendstring)
{
sf::Lock mylock2(mymutex);
if(!ircsocket.send(sendstring.c_str(),sendstring.size()+1))
{
status = "send failed!";
}
}
void login (std::string ip,std::string port)
{
int int_port;
int_port = stringtonumber(port);
if(!ircsocket.connect(address,int_port))
{
status = "connect failure";
std::cout<<sock_status;
}
else
{
dont_connect = true;
if(!ircsocket.send(buffer,sizeof(buffer))!=sf::Socket::Done)
{
std::cout<<"socket error: "<<sock_status;
}
else
{
status = "Connected!";
connected = true;
}
}
}
|