Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Soul

Pages: [1] 2 3
1
Network / Re: nonblocking sockets
« on: June 02, 2014, 04:11:01 pm »
okey, thanks for help, but atm i don't know how to use non-blocking sockets, with selector? or what..., i'm nerd in network programing, i make only simple ircbot and multichat with blockingsockets, but i don't want use threads in my game : D

2
Network / nonblocking sockets
« on: May 31, 2014, 04:45:38 pm »
Hey, i should use nonblocking sockets in my game to make her real-time, and my question, can i use selectors to make server multiclient? or better way is multithread with nonblocking sockets?

3
Network / receive timeout don't work
« on: May 29, 2014, 05:45:48 pm »
Hey, i have this code, and i don't know why timeout don't work...
void Server::update()  /// stupid sending packets...
{
    for( std::vector<Client*>::iterator it = clients.begin(); it!= clients.end(); ++it )
    {
        Client &client = **it;
        if (Selector.wait(sf::milliseconds(500)))
        {
            if(Selector.isReady(client.Socket))
            {
                if ( client.Recv(50) )
                {
                 ...
                }
                else                    /// This line never do...
                SendMapInfo();
            }
        }
    }
}

bool Client::Recv(float t)
{
    send.clear();
    recv.clear();
    sf::SocketSelector selector;
    selector.add(Socket);
    if( selector.wait(sf::milliseconds(t)))
    {
        if(Socket.receive(recv)== sf::Socket::Done)
        {
            recv >> family >> action;
            return true;
        }
        else return false;
    }
    else return false;
}
 

4
Network / player info sending
« on: May 27, 2014, 05:26:12 pm »
Hey, i have problem with my loop to sending player info to other clients, when 2 players are connecter everything work okey, but when third connect, to the third player is sending too much packets with players info..., i can't see what's wrong with my loop : o, any ideas?
void Server::SendMapInfo()
{
    for( std::list<Client*>::iterator it = clients.begin(); it!= clients.end(); ++it )
    {
        Client &client = **it;
        if(inGameClients.size()>1)
        {
            for( std::list<Client*>::iterator itt = inGameClients.begin(); itt!= inGameClients.end(); ++itt )
            {
                Client &temp = **itt;
                if(temp.ClientID!=client.ClientID&&client.inGame==true&&temp.inGame==true)
                {
                    //if(temp.Char.X/maps[client.Char.MapID]->tilesize<(client.Char.X/maps[client.Char.MapID]->tilesize-8)
                        // || temp.Char.X/maps[client.Char.MapID]->tilesize>(client.Char.X/maps[client.Char.MapID]->tilesize+8) )
                    //  {
                    //    if(temp.Char.Y/maps[client.Char.MapID]->tilesize<(client.Char.Y/maps[client.Char.MapID]->tilesize-8)
                        //  || temp.Char.Y/maps[client.Char.MapID]->tilesize>(client.Char.Y/maps[client.Char.MapID]->tilesize+8) )
                        //{
                            client.family=Packet::PACKET_WORLD;
                            client.action=Packet::PACKET_REQUEST;
                            client.send<<client.family<<client.action<<temp.Char.Name<<temp.ClientID<<temp.Char.X<<temp.Char.Y;
                            client.Send();
                            std::string str;
                            str=std::to_string(temp.ClientID);
                            str+=" ";
                            str+=temp.Char.Name;
                            str+=" ";
                            str+=std::to_string(temp.Char.X);
                            str+= " ";
                            str+=std::to_string(temp.Char.Y);
                            client.SMsg(str.c_str());
                        // }
                    // }
                }
            }
        }
    }
}

5
Network / server does not recv packets
« on: May 27, 2014, 08:04:27 am »
Hey, when to my server connect first client everything work fine, but then i want connect other clients server stop receiving packets from other clients. I use tcp sockets with blocking mode and timeout use, what's wrong? : /
bool Client::Recv()
{
    sf::Socket::Status status = Socket.receive( recv );
    if ( status == sf::Socket::Done ) { recv >> family >> action; return true; }
    else return false;
}

bool Client::Recv(float t)
{
    send.clear();
    recv.clear();
    sf::SocketSelector selector;
    selector.add(Socket);
    if( selector.wait(sf::milliseconds(t)))
    {
        if(Socket.receive(recv)== sf::Socket::Done)
        {
            recv >> family >> action;
            return true;
        }
        else return false;
    }
    else return false;
}
 

void Server::update()  /// stupid sending packets...
{
    for( std::list<Client*>::iterator it = clients.begin(); it!= clients.end(); ++it )
    {
        Client &client = **it;
        if(Selector.wait(sf::milliseconds(50)))
        {
            if ( client.Recv(0.3) )
            {
        ///        std::cout<<Packet::GetFamilyName(client.family)<< " "<<Packet::GetActionName(client.action)<<std::endl;
         ///       std::cout<<client.family<< " "<<client.action<<std::endl;
                if( client.family == Packet::PACKET_A_INIT )
                {
                    if( client.action == Packet::PACKET_REQUEST )  /// connection initialize
                    {
                        client.InitA();
                    }
                    else    /// error in init1
                    {
                        Selector.remove( client.Socket );
                        clients.erase(it);
                        --it;
                    }
                }
                else if( client.family == Packet::PACKET_B_INIT )
                {
                    if( client.action == Packet::PACKET_REQUEST )
                    {
                        client.InitB();
                    }
                    else   /// as above but with init2
                    {
                        Selector.remove( client.Socket );
                    clients.erase(it);
                    --it;
                    }
                }
                else if( client.family == Packet::PACKET_ACCOUNT && client.action == Packet::PACKET_REQUEST)
                {
                    if(client.CreateAccount())
                    {
                    }
                }
                else if( client.family == Packet::PACKET_LOGIN && client.action == Packet::PACKET_REQUEST )
                {
                    client.Login();
                }
                else if( client.family == Packet::PACKET_CHARACTER && client.action == Packet::PACKET_CREATE )
                {
                    client.CreateCharacter();
                }
                else if( client.family == Packet::PACKET_CHARACTER && client.action == Packet::PACKET_REQUEST )
                {
                    client.LoginChar();
                }
                else if( client.family==Packet::PACKET_MOVE && client.action==Packet::PACKET_REQUEST )
                {
                    client.RMsg();
                    client.Move(maps[client.Char.MapID]);
                }
                else if( client.family == Packet::PACKET_DISCONNECT && client.action==Packet::PACKET_REQUEST ) /// disconnecting xD
                {
                    if( client.Disconnect() )
                    {
                        Selector.remove( client.Socket );
                        clients.erase(it);
                        --it;
                    }
                }
            }
//            else if(client.inGame)
  //          {
                //SendMapInfo();
    //        }
        }
    }
}
 
@solved
i change in update selector.wait to selector.isReady and now work with small bugs :v

6
General / Re: strange problem
« on: May 14, 2014, 12:04:05 pm »
http://www44.zippyshare.com/v/1075079/file.html

here is complete my mapeditor source code, the problem is in menu.h, if you can compile it in debug mode (not debuger...)
then use  one of variables in comments and check what's wrong, my debuger can't nothing find because everything work fine

7
General / Re: strange problem
« on: May 13, 2014, 01:30:22 pm »
it crash in debug mode only lol, it crash when i declare one typ
in this code everything is ok, to crash i must declare one variable... i'll try later rebuild my debug mode libs, maybe it help...
app crash at startup, it's strange, anyway i can upload my project and you can compile it and check, maybe it crashesh only on my i5 hmmm

8
General / Re: strange problem
« on: May 13, 2014, 12:54:38 pm »
well, my english isn't pretty good, sorry, anyway my problem is with this class, at the moment everything work fine, but when i declare one more type upper than char (for eg. int or float) app will it crash, in debuger everything work fine too, i was tryed use pointers, but it don't work too :PP, problem can be with memory?
#ifndef MENU_H
#define MENU_H
#include <TGUI/TGUI.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include "../include/Map.h"
#define THEME_CONFIG_FILE "gui/BabyBlue.conf"

class Menu
{
    public:
        void LoadMenu(sf::RenderWindow &wnd);
        bool Callback(Map &m);
        void Event(sf::Event &event);
        void Draw();
        void hide();
        void getTile();
    protected:
    tgui::Gui gui;
    tgui::Gui tilegui;
    tgui::MenuBar::Ptr menu;
    tgui::Callback callback;
    tgui::ChildWindow::Ptr window;
    tgui::Button::Ptr Create;
    tgui::Button::Ptr Load;
    tgui::EditBox::Ptr name;
    tgui::EditBox::Ptr tilepath;
    tgui::EditBox::Ptr objectpath;
    tgui::EditBox::Ptr tilesize;
    tgui::EditBox::Ptr x;
    tgui::EditBox::Ptr y;
    sf::RenderWindow *W;
    sf::RenderWindow T;
    sf::Sprite tilespr;
    sf::Texture *tex;
    sf::Vector2i pos;
    sf::Mouse mouse;
    sf::Vector2i WinPos;
    bool showT;
    bool showM;
    Map *mapa;
};

9
General / strange problem
« on: May 13, 2014, 12:27:54 pm »
Hey, i have problem with my map editor, i don't know why, but when i add one more object from tgui, sfml and type higher than char my app crash, only in menu class, why?, when i debug everything work fine, but when i want run exe it crash...

that print console
Quote
Process returned -1073741676 (0xC0000094)   execution time : 2.281 s
Press any key to continue.

10
General / app crash with vector2i in for()
« on: May 11, 2014, 04:39:25 pm »
Hey, i have this code
it work fine
void Map::Draw( sf::RenderWindow &wnd)
{
    if(isDraw)
    {
        for(int i=0; i<TileList.size();i++)
        {
            for(int j=0; j<TileList[i].size();j++)
            {
                if(TileList[i][j]->SpriteX==-1&&TileList[i][j]->SpriteY==-1)
                {
                    rect.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    wnd.draw(rect);
                }
                else
                {
                    TileSet.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    TileSet.setTextureRect( sf::IntRect(TileList[i][j]->SpriteX*tilesize, TileList[i][j]->SpriteY*tilesize,tilesize, tilesize) );
                    wnd.draw(TileSet);
                }
            }
        }
    }
}


but when i do something like this, the app will crash, why?
void Map::Draw( sf::RenderWindow &wnd)
{
    if(isDraw)
    {
        for(int i=0; i<Pos.x+10;i++)
        {
            for(int j=0; j<Pos.y+10;j++)
            {
                if(TileList[i][j]->SpriteX==-1&&TileList[i][j]->SpriteY==-1)
                {
                    rect.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    wnd.draw(rect);
                }
                else
                {
                    TileSet.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    TileSet.setTextureRect( sf::IntRect(TileList[i][j]->SpriteX*tilesize, TileList[i][j]->SpriteY*tilesize,tilesize, tilesize) );
                    wnd.draw(TileSet);
                }
            }
        }
    }
}

11
Window / Re: problem with unactive window and events
« on: May 03, 2014, 04:52:09 pm »
u use sf::Keyboard, hmm so i must code a simple function to make the solution, thanks for help :)

12
Window / problem with unactive window and events
« on: May 03, 2014, 04:13:10 pm »
Hey, i have a problem with renderwindow and events, when my mouse is outside window, this window capture mouse position and keyboard events, how can i disable that functions?

13
General / Re: tgui childwindow example
« on: April 09, 2013, 05:09:28 pm »
oh, okay, thanks, i'm so f*ckin stupid xD
i must remember that : o

14
General / Re: tgui childwindow example
« on: April 09, 2013, 04:21:57 pm »
awwwwww, when i click buttons create and login i have the same error http://s1.pokazywarka.pl/bigImages/1910820/6810469.jpg
i hate work on pointers xD

#include "include/Client.h"
#include <TGUI/TGUI.hpp>
int main()
{
    Client client;
    sf::RenderWindow window(sf::VideoMode(800, 600), "Client");
    sf::Clock Framerate;
    float acu = 0;
    float frametime = 0.01;

    tgui::Form Wnd( window );
    tgui::Panel::Ptr Menu(Wnd);
    tgui::Panel::Ptr Create(Wnd);
    tgui::Panel::Ptr Login(Wnd);
    Login->load( 800, 600);
    Create->load(800,600);
    Menu->load(800,600);
    Menu->setGlobalFont( "Font/djvs.ttf");
    Create->setGlobalFont( "Font/djvs.ttf");
    Login->setGlobalFont( "Font/djvs.ttf");

    tgui::Button::Ptr connect(*Menu);
    tgui::Button::Ptr disconnect(*Menu);
    tgui::Button::Ptr createaccount(*Menu);
    tgui::Button::Ptr create(*Create);
    tgui::Button::Ptr login(*Login);

    tgui::Label::Ptr labelUsername(*Create);
    labelUsername->setText("Username:");
    labelUsername->setPosition(200, 70);
    labelUsername->setTextSize(10);
    Create->add(labelUsername);

    tgui::Label::Ptr labelPassword(*Create);
    labelPassword->setText("Password:");
    labelPassword->setPosition(200, 230);
    labelPassword->setTextSize(10);
    Create->add(labelPassword);

    tgui::Label::Ptr labelMail(*Create);
    labelMail->setText("E-Mail:");
    labelMail->setPosition(200, 370);
    labelMail->setTextSize(10);
    Create->add(labelMail);

    tgui::EditBox::Ptr editBoxUsername(*Create, "Username");
    editBoxUsername->load("gui/EditBox/Black");
    editBoxUsername->setSize(100, 40);
    editBoxUsername->setPosition(200, 90);
    editBoxUsername->setMaximumCharacters( 15 );
    editBoxUsername->setTextSize(10);
    Create->add(editBoxUsername, "Username" );

    tgui::EditBox::Ptr editBoxPassword(*Create, "Password");
    editBoxPassword->load("gui/EditBox/Black");
    editBoxPassword->setPosition(200, 250);
    editBoxPassword->setSize(100, 40);
    editBoxPassword->setPasswordChar('*');
    editBoxPassword->setMaximumCharacters( 15 );
    editBoxPassword->setTextSize(10);
    Create->add(editBoxPassword, "Password");

    tgui::EditBox::Ptr editBoxMail(*Create, "E-Mail");
    editBoxMail->load("gui/Editbox/Black");
    editBoxMail->setSize(100,40);
    editBoxMail->setPosition(200, 390);
    editBoxMail->setTextSize(10);
    Create->add(editBoxMail, "E-Mail");

    tgui::EditBox::Ptr editBoxLogin( *Login, "Username" );
    editBoxLogin->load("gui/Editbox/Black");
    editBoxLogin->setSize(100, 40);
    editBoxLogin->setPosition(100,100);
    editBoxLogin->setMaximumCharacters( 15 );
    editBoxLogin->setTextSize(10);
    Login->add(editBoxLogin, "Username");

    tgui::EditBox::Ptr editBoxPass( *Login, "Password" );
    editBoxPass->load("gui/Editbox/Black");
    editBoxPass->setSize(100, 40);
    editBoxPass->setPosition(220,200);
    editBoxPass->setMaximumCharacters( 15 );
    editBoxPass->setTextSize(10);
    Login->add(editBoxPass, "Password");

    createaccount->load("gui/Button/Black");
    createaccount->setSize(100, 50);
    createaccount->setPosition(270, 280);
    createaccount->setText("Create Account");
    createaccount->bindCallback(tgui::Button::LeftMouseClicked);
    createaccount->setCallbackId(1);
    createaccount->setTextSize(10);

    connect->load("gui/Button/Black");
    connect->setSize(100, 50);
    connect->setPosition(270, 340);
    connect->setText("Connect");
    connect->bindCallback(tgui::Button::LeftMouseClicked);
    connect->setCallbackId(2);
    connect->setTextSize(10);

    disconnect->load("gui/Button/Black");
    disconnect->setSize(100, 50);
    disconnect->setPosition(270, 400);
    disconnect->setText("Disconnect");
    disconnect->bindCallback(tgui::Button::LeftMouseClicked);
    disconnect->setCallbackId(3);
    disconnect->setTextSize(10);

    create->load("gui/Button/Black");
    create->setSize(100, 50);
    create->setPosition(400, 100);
    create->setText("Register");
    create->bindCallback(tgui::Button::LeftMouseClicked);
    create->setCallbackId(4);
    create->setTextSize(10);

    login->load("gui/Button/Black");
    login->setText("Login");
    login->setSize(100,50);
    login->setPosition(400,400);
    login->bindCallback(tgui::Button::LeftMouseClicked);
    login->setCallbackId(5);
    login->setTextSize(10);

    Menu->add(createaccount);
    Menu->add(disconnect);
    Menu->add(connect);
    Login->add(login);
    Create->add(create);


    int menu = 1;
    while (window.isOpen())
    {
        acu += Framerate.restart().asSeconds();
        sf::Event event;
        /// input
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            Wnd.handleEvent(event);

        }               /// end of input

        /// logic
        if( acu > frametime)
        {
            tgui::Callback callback;
            while (Wnd.pollCallback(callback))
            {
                switch( callback.callbackId)
                {
                    case 1:
                    {
                        if( client.init( "127.0.0.1", 6667 ))
                        {
                            menu = 2;
                        }
                        else menu=1;
                        break;
                    }
                    case 2:
                    {
                        if( client.init( "127.0.0.1", 6667 ) )
                        {
                            menu = 3;
                        }
                        else menu=1;
                        break;
                    }

                    case 3:
                    {
                        client.Disconnect();
                        menu = 1;
                        break;
                    }
                    case 4:
                    {
                        editBoxUsername = Wnd.get("Username");
                        editBoxPassword = Wnd.get("Password");
                        editBoxMail = Wnd.get("E-Mail");
                        sf::String username = editBoxUsername->getText();
                        sf::String password = editBoxPassword->getText();
                        sf::String email = editBoxMail->getText();
                        editBoxUsername->setText("");
                        editBoxPassword->setText("");
                        editBoxMail->setText("");
                        std::string user = username.toAnsiString();
                        std::string pass = password.toAnsiString();
                        std::string mail = email.toAnsiString();
                        if( user.size() >= 4 && pass.size() >= 6 && mail.find("@") && mail.size() >=8 )
                        {
                            int data;
                            client.Send << Packet::PACKET_ACCOUNT << Packet::PACKET_REQUEST << user; /// pytanie czy konto o danej nazwie juz istnieje
                            client.ServerSock.send( client.Send );
                            client.ServerSock.receive(client.Recv);
                            client.Recv >> client.family >> client.action >> data;
                            client.Send.clear();
                            client.Recv.clear();
                            if( client.family == 2 && client.action == 2)
                            {
                                if( data == 0 ) /// jesli istnieje przerywa polaczenie
                                {
                                    std::cout<<"Konto o tym loginie juz istnieje"<<std::endl;
                                    editBoxUsername->setText(user);
                                    editBoxPassword->setText(pass);
                                    editBoxMail->setText(mail);
                                    client.Disconnect();
                                    menu=1;
                                }
                                else if( data == 1 ) /// jesli nie wysyla haslo i maila potrzebne przy tworzeniu konta
                                {
                                    client.Send << Packet::PACKET_ACCOUNT << Packet::PACKET_CREATE << pass << mail;
                                    client.ServerSock.send(client.Send);
                                    client.Send.clear();
                                    client.ServerSock.receive(client.Recv);
                                    client.Recv >> client.family >> client.action >> data;
                                    if( client.family == 2 && client.action==1 )
                                    {
                                        if( data == 1 )  /// konto utworzono
                                        {
                                            std::cout<<"utworzono konto: "<< user << " " << pass << " " << mail << std::endl;
                                            client.Disconnect();
                                            menu=1;
                                        }
                                            /// blad przy tworzeniu
                                        else if(data==0)
                                        {
                                            std::cout<<"Nie moge stworzyc konta" <<std::endl;
                                            client.Disconnect();
                                            menu=1;
                                        }
                                        else
                                        {
                                            std::cout<<"Nieznany problem przy tworzeniu konta" <<std::endl;
                                            client.Disconnect();
                                            menu=1;
                                        }
                                    }
                                    else
                                    {
                                        client.Disconnect();
                                        std::cout<<"nieznany error: " << data<<std::endl;
                                        menu=1;
                                    }
                                }
                            }
                            else
                            {
                                client.Disconnect();
                                menu=1;
                            }
                            break;
                        }
                    }
                    case 5:
                    {
                        editBoxLogin = Wnd.get("Username");
                        editBoxPass = Wnd.get("Password");
                        sf::String username = editBoxLogin->getText();
                        sf::String password = editBoxPass->getText();
                        editBoxLogin->setText("");
                        editBoxPass->setText("");
                        std::string user = username.toAnsiString();
                        std::string pass = password.toAnsiString();
                        if( user.size() >=4 && pass.size() >= 6 )
                        {
                            int data;
                            client.Send << Packet::PACKET_LOGIN << Packet::PACKET_REQUEST << user;
                            client.ServerSock.send(client.Send);
                            client.ServerSock.receive(client.Recv);
                            client.Recv >> client.family >> client.action >> data;
                            if(client.family==3 && client.action==2)
                            {
                                if( data == 1)
                                {
                                    client.Send.clear();
                                    client.Recv.clear();
                                    client.Send << Packet::PACKET_LOGIN << Packet::PACKET_REPLY << pass;
                                    client.ServerSock.send(client.Send);
                                    client.ServerSock.receive(client.Recv);
                                    client.Recv >> client.family >> client.action >> data;
                                    client.Send.clear();
                                    client.Recv.clear();
                                    if( client.family==3 && client.action==1)
                                    {
                                        if(data==0)
                                        {
                                            std::cout << "Podano zle haslo" << std::endl;
                                            client.Disconnect();
                                            menu=1;
                                        }
                                        else if(data==1)
                                        {
                                            std::cout << "Zalogowano"<<std::endl;
                                            menu=1;
                                            break;
                                        }
                                        else if(data==2)
                                        {
                                            std::cout << "Konto w uzyciu" << std::endl;
                                            client.Disconnect();
                                            menu=1;
                                        }
                                        else
                                        {
                                            std::cout << "Nieznany blad: " << data << std::endl;
                                            client.Disconnect();
                                            menu=1;
                                        }
                                    }
                                    else std::cout<<"problemy z pakietem 2"<<std::endl; client.Disconnect(); menu=1;
                                }
                                else
                                {
                                    std::cout<< "Nie ma takiego konta"<<std::endl;
                                    client.Disconnect();
                                    menu=1;
                                }
                            }
                            else std::cout<<"problemy z pakietem 1"<<std::endl; client.Disconnect(); menu=1;
                        }
                        break;
                    }
                }
            }
        }
            /// end of logic

    /// drawing
    window.clear();
        switch(menu)
        {
            case 1:
            {
                Login->hide();
                Create->hide();
                Menu->enable();
                Login->enable();
                Create->enable();
                Menu->show();
                Wnd.draw();
                break;
            }
            case 2:
            {
                Create->show();
                Login->hide();
                Menu->hide();
                Wnd.draw();
                break;
            }
            case 3:
            {
                Login->show();
                Create->hide();
                Menu->hide();
                Wnd.draw();
                break;
            }
        }
    window.display();  /// end of drawing
    }
}
 

15
General / Re: tgui childwindow example
« on: April 09, 2013, 03:07:33 pm »
thanks for help, now everything work fine :)

Pages: [1] 2 3
anything