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

Author Topic: player info sending  (Read 2152 times)

0 Members and 1 Guest are viewing this topic.

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
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());
                        // }
                    // }
                }
            }
        }
    }
}

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: player info sending
« Reply #1 on: May 27, 2014, 06:03:30 pm »
  • I have absolutely no idea what that code does.
  • I have absolutely no idea what you want the code to do. Read this?
  • Why is this in the General forum?
  • What exactly does this have to do with SFML?
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: player info sending
« Reply #2 on: May 30, 2014, 04:14:52 pm »
You may want to research good programming practices and design.

Why the heck are you concatenating values at strings, this code is bloated, practically obfuscated and unreadable.

 

anything