send x,y-positions?

This is a discussion on send x,y-positions? within the Game Programming forums, part of the General Programming Boards category; hi the game im making requires multiplaying over the net. so i thought i should use winsock for this. but ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    send x,y-positions?

    hi
    the game im making requires multiplaying over the net.
    so i thought i should use winsock for this.
    but ive never made a multiplayer game before, so i need some advice from those who have experience on this.

    my idea is this:
    say i have a player-x.y-pos and a bullet x,y-pos.
    should i send these to the next computer and there show them on screen.
    if thats a good idea then how does the receiver know which is wich.
    maybe this is fixed very easily cause my knowledge of winsock isnt much.

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    That would cause a lot of network traffic if you shoot often. I think you should tell the other computer where the bullet's been shot and the direction and let the it compute the next positions.
    I've never actually done this, but it seems like it could work.

    In answer to your second question, you could prefix the user and bullet with a keyword, maybe something like:
    Code:
    ...
    char [128] buffer {0};
    char [128] temp {0};
    //set prefix for the player data
    strcat(buffer, "PLAYER ");
    GetPlayerXY(temp); //this function should pass a char array into temp;
    strcat(buffer, temp); 
    send(hSocket, buffer, strlen(buffer)-1);//send the data
    The other computer woudl receive something like: "PLAYER -10 5" for example. You should parse that to get what yo need. The shot could be something like:
    SHOT PosX PosY DIRECTIONOFBULLET

    Also, this should be in the networking forum.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    so then i need to cut up the string on the receiving computer
    is there a function for that?

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I wouldn't recommend the players' computers sending the information to the other players' computers. A more secure way would be the player sending the information to the server and the server then sending the information to everyone's computer. That would get around people hacking their game to get clipping turned off, infinite ammo, etc. A lot of times the server computer is fast, so it could speed the gameplay up a hair.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    I wouldn't recommend the players' computers sending the information to the other players' computers.
    youre right casue i DONT want to do THAT myself. i mean
    running 1 km and back.. pheew

    A lot of times the server computer is fast, so it could speed the gameplay up a hair.
    not if you have timebased movement

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    hmm i made a small program and tryed it out
    it works but not with bigger numbers

    i did it like this:

    Code:
    
    #include <iostream.h>
    
    
    #include <string.h>
    #include <stdio.h>
    
    
     
    
    void main( void )
    {
    	int  ch = ':';
        char string[] = "PL";
    
        char *pdest;
        int tal;
        int x=47;
        int y=65;
        int *px=&x;
        int *py=&y;
        int  klon=':'; 
        int *k=&klon;
        int result;
        char buffer[]="1234567890123456789";
    
     
    	cout<<"string before "<<string<<"\n";
      
    	strcat(string,(char(*))k);
    	strcat(string,(char(*))px);
    	strcat(string,(char(*))k);
    	strcat(string,(char(*))py);
    
    	
    
    	cout<<"string after "<<string;
    
    
    	pdest= strchr(string,ch);
    	
    
    	result=pdest-string+1;
    
    	tal=strlen(string);
        tal=tal-result;
    
        cout<<"\nfound "<<*pdest<<" at position "<<" "<<result<<" with "<<tal<<" positions remaining";
    
        cout<<"\nx is "<<(int)string[result];
    
    	strcpy(buffer,string);
    
        cout<<"\n this is buffer "<<buffer;
      
      
    
        pdest= strrchr( string, ch );
        result=pdest-string+1;   
        tal=strlen(string);
        tal=tal-result;
        cout<<"\nfound next "<<*pdest<<" at position "<<" "<<result<<" with "<<tal<<" positions remaining";
    
        strcpy(buffer,pdest+1);
    
        cout<<"\ny is "<<(int)buffer[result];
    
    
    	///the output is PL:xpos:ypos   as i said i used the : to seperate them
    
       
    }
    does anyone know of a better way

    ps maybe i did wrong to post this in this forum can a mod pls
    move it to the networkforum if its in the wrong one..
    Last edited by pode; 11-17-2003 at 05:19 PM.

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    not if you have timebased movement
    So you're saying that if you had to send 5 megabytes of data every frame from a dial-up connection you won't have a single bit of lag, because it uses time-based movement? I was talking about lag, not the movement of the actual objects on screen.

    edit: oh, yeah, and you misinterpretted yet ANOTHER part of my post. I said I wouldn't recommend the players' computer sending the data to the other players' computers. You had to try and be funny and focus on cheap humor, instead of reading my whole post. You DO NOT want to send the data in a p2p fasion. It is so easy to cheat it, it's not even funny. Oh, my bad, you probably don't know what p2p means, look up peer-to-peer on the internet. Use google.
    Last edited by frenchfry164; 11-17-2003 at 08:48 PM.

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    why u get so mad. as you said it was just a cheap joke.
    and im not not gonna make doom 3. i just want to try to make a multiplayers game. and then i will make sure the connection speed is good

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    So you're saying that if you had to send 5 megabytes of data every frame
    thats 40 000 000 bits/frame
    and by frame you better mean a second
    i doubt any game does this.

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    does anyone got an idea of how to do it properly

  11. #11
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    your best bet is a client-server model.
    once you make a connection to the server you'll probley only send a few messages to it.

    your location, movement, and direction.
    if and what your shoting.(i.e. your pistol or aka)
    chat or admin commands.
    and a very small BITE to signal that your stats has not changed.
    like when you leave for a minute.

    what you should recive from the server is basicly every thing from above for all the clients connected. including yours.
    that be called a snapshot.
    it be basicly a picture of everything going on at a given moment.

    now there are many ways to optimize the snapshot for each client but if you get 100ppl in there then the processer overhead my be to much for the server.(advance topic).

    basicly the snap will contain
    Code:
    {
        int Xpos,
        int Ypos,
        CVECTOR dir, //(x,y,z)
        int weapon,
        int StatusFlag //first bit ducking, second bit jumping,
                       // third bit running etc.
    }
    if you ask some for questions i might be able to help

    [edit]
    please note that only the origional author is a hacker. all the puck ass mother $$$$ers that use the software are called cheaters.

    you can limit their effect but you can never stop an aimbot or wallhack b/c they work inside your restrictions.
    you can check and make sure that the client is not trying to warp to a location by testing its 'pos' to know if it is a valid move.

    never let the client manage its on health/armor/'weapons/ammo. that be what the server is there for.

    never let the client send a message saging i killed/damaged 'player #id'

    only let them send a message saying they shot in this direction.

    if you do all that then the noobs who make cheats will give up for easier game. but there is always the poticheal for a pro to come in and mess with things. they usually only take a few hours for someone how knows what their doing.
    Last edited by Nor; 11-19-2003 at 11:30 AM.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    ok.. but how do you pack this into a const char cause that is the only way that i know of sending

  13. #13
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    read my edit

    the easyest what is to phrase the incomming information on the socket. (tech example)

    there are 2 easy ways.
    the first thing you can send be a length. then you just read in that much information.
    the second be by making a symble that will tell you that this be the end of the packet. one problem with this. if this symble is ever sent then it in the data and not at the end of a packet then your server will get confused and the data will get disjointed.


    i usually make a large buffer and fill it/read it/ then flush.
    fill it- get the length from the socket. MAKE SURE IT DOES -NOT- OVERFLOW YOUR BUFFER and then read in that much data from the socket.

    you will have to send the data as structs. do not use points for they will not work at the other end. they only be good for the process on the machine they be created on. but you probleyy new that

    readit - best bet would be to share a header file between you client and server code and then just
    memcpy(YourStructerBuffer, FromYourSocketBuffer, sizeof(mystructer));
    mystructer be declared in the shared headerfile. you could put it in 2 different files but that be messy when you need changes

    what else?

    [edit]
    speaking of buffers. for now a char buffer will work. but an unsigned char buffer be the prober way to do it. mainly cause of the unsigned part.
    someone correct me if i be wrong.
    when you use just a char buffer then the first bit of each char will be set to 1. so if your going to read this in as in int/float/whatever then the information could be wrong and every 8th bit be set. that be a mouth full
    Last edited by Nor; 11-19-2003 at 11:48 AM.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  14. #14
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    sorry missed the meaning of that question.
    it doesnt matter what type of buffer you want to send only that you know whats in it and can type sizeof(mybuffer) in the

    send(socket,buffer,sizeof(buffer),flags);
    statment.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  15. #15
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    im getting confused so i can send a struct instead of a const char?
    i didnt know that was possible.
    you wouldnt have any example code to show?

    btw i have made aserver-client test program for my game

    try it out

    use the arrows to move
    and be sure to open the one named spelserv first

    ooops forgot to attach it see next post
    Last edited by pode; 11-19-2003 at 12:05 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tuncated uint8_t
    By Coens in forum C Programming
    Replies: 14
    Last Post: 11-24-2008, 07:57 AM
  2. nonblocking send need help
    By sleith in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-27-2008, 11:51 PM
  3. sending n no of char data uning send() function,
    By thebrighter in forum Windows Programming
    Replies: 1
    Last Post: 08-22-2007, 01:26 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 12:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21