hello everyone,

I just tried to put my hands on the gamestudio multiplayer engine again. The last time I did that, I ended up nearly exclusively using send_data - only to get something in the direction of client side prediction working. But now I found the new 3rd value for dplay_smooth, which stops the engine predicting the players movement. So I wrote a small code, that lets you control a player with your keyboard.

The only problem is, that I give the client too much power by letting him choose the position he wants to spawn. Whats the best way to avoid that? The greatest problem I see is that you can only use some handy functions like proc_client and everything that is related to checking where the entity belongs to, when you executed that ent_create on a client - what I think is a no go...

How should I rewrite my code to conform with these conditions?

Thank you
Scorpion

Here's the code I hacked together:
Code:
#define rand_area(x) vector(x-2*random(x),x-2*random(x),x-2*random(x))

#define KEYS skill1
#define SPEED skill2
#define ASPEED skill3

#define KEY_FORWARD    (1<<0)
#define KEY_BACKWARD    (1<<1)
#define KEY_LEFT        (1<<2)
#define KEY_RIGHT        (1<<3)
#define KEY_SHOOT        (1<<4)

#define k(x) sign(my.KEYS & (x)) //is key pressed?

//movement code for player - executed on server and client
void player_move(){
    var dirX = k(KEY_FORWARD) - k(KEY_BACKWARD);
    DEBUG_VAR(dirX, 30);
    var dirY = k(KEY_LEFT) - k(KEY_RIGHT);
    
    my.pan += accelerate(my.ASPEED, dirY*10, 0.7);        
    c_move(me, vector(accelerate(my.SPEED, dirX*10, 0.7), 0, 0), nullvector, IGNORE_PASSABLE);
}

//player action on client
void player_main_client(){
    while(1){
        //store keys in skill
        my.KEYS =       key_w            *KEY_FORWARD
                        | key_s            *KEY_BACKWARD
                        | key_a            *KEY_LEFT
                        | key_d            *KEY_RIGHT
                        | mouse_left    *KEY_SHOOT;
        
        send_skill(my.KEYS, SEND_VEC|SEND_UNRELIABLE);
        player_move();
        
        //adapt camera to new position
        vec_set(camera.x, my.x);
        vec_set(camera.pan, my.pan);
        
        wait(1);
    }
}

//player action on server
action player_main(){
    proc_client(me, player_main_client);
    
    while(1){
        player_move();
        wait(1);
    }
}

int main(){
    dplay_smooth = 3;//client side player-entity is not updated
    
    while(1){
        if(key_1){//server
            if(!session_open("ilovecake")){
                sys_exit("Couldn't create session!");
            }
            
            level_load(NULL);
            break;
        }
        if(key_2){//client
            session_connect("ilovecake", "127.0.0.1");
            while(!connection) wait(1);
            level_load(NULL);
            randomize();
            player = ent_create(SPHERE_MDL, vec_add(rand_area(50),vector(0,0,50)), player_main);
            
            break;
        }
        wait(1);
    }    
    return 0;
}



Last edited by Scorpion; 07/17/10 13:35. Reason: changed code to not require external resources for purpose of easy testing