Well, after a day of raging I still havnt gotten it working.
Any ideas on how to get it all working properly?
I have taken out the data/user/login/etcetc, so it obviously wont run, same with the custom includes. But hopefully it shouldnt matter for this problem.
Basically, need to get the receive stuff working with the graphics stuff.
Now that im (not?) using threads, dont know if this thread should stay under "Systems", but oh well.
#define _CRT_SECURE_NO_WARNINGS
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <sstream>
#include "misc.h"
#include "f.h"
#include "md5.h"
sf::SocketTCP Client;
sf::SelectorTCP Selector;
std::string STX = "\x02";
std::string ETX = "\x03";
std::string SOH = "\x01";
int main(){
std::vector<std::string> results;
std::stringstream all;
std::string ReceivedStr;
size_t Size = 0;
char Buffer[1];
std::vector<std::string> gInfo = fLogin("", "");
std::string hood = "";
std::string server = fServer(hood);
Client.Connect(8080, server);
//Client.SetBlocking(false);
Selector.Add(Client);
fSend(Client, "some,data");
fSend(Client, "some,data");
fSend(Client, "some,data");
sf::Event Event;
sf::RenderWindow App(sf::VideoMode(1024, 1024, 32), "SFML Graphics");
sf::Image Map;
sf::Image avatarMe;
Map.LoadFromFile("image1.jpg");
avatarMe.LoadFromFile("1aff79cba4bac.png");
sf::Sprite Flash(Map);
sf::Sprite Sprite(avatarMe);
while(App.IsOpened()){
while(App.GetEvent(Event)){
if (Event.Type == sf::Event::Closed)
App.Close();
}
float ElapsedTime = App.GetFrameTime();
if (App.GetInput().IsKeyDown(sf::Key::Left)) Sprite.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Up)) Sprite.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down)) Sprite.Move(0, 100 * ElapsedTime);
App.Clear();
App.Draw(Flash);
App.Draw(Sprite);
App.Display();
if(Selector.Wait()){
Client.Receive(Buffer, sizeof(Buffer), Size);
ReceivedStr.append(Buffer, Buffer + Size);
if(Size <= sizeof(Buffer)){
if(ReceivedStr != ETX){
all << ReceivedStr;
}else{
if(all.str().length() > 2){
if(!isdigit(all.str().substr(0, 1)[0]))
all.str(all.str().substr(1, all.str().length()));
StringExplode(all.str(), STX, &results);
switch(atoi(results[0].c_str())){
case 35:
std::cout << all.str() << std::endl;
break;
default:
std::cout << all.str() << std::endl;
break;
}
}
all.str("");
}
ReceivedStr = "";
results.clear();
}
}
}
std::cout << "Press enter to exit..." << std::endl;
std::cin.ignore(10000, '\n');
Client.Close();
return EXIT_SUCCESS;
}