Jump to content
AXEL777

client-server side requests parameters

Recommended Posts

Hi guys! I have a small question for the experts of this language.

I am writing my client-server mod and I need to organize the exchange of information between the server and the game client on request from the game client.

I can not understand the following:

On the server side, there are 3 variables in my class with values of int, bool, and string types. On the client side of the game I need for each player to pass these parameters at the time of connection to the server for further correct operation of the script.

How do I request these parameters from the client and receive the values from the server in a response message? Explain please! Preferably with examples.

Share this post


Link to post
Share on other sites

For this I think you have to use Community framework.

You have an exemple of client-server communication on the github and maybe if you replace the "override void OnKeyPress" with an apropiate void you can send message to the server when a client is connecting (didn't try but I think something like that should works)

 

 

 

Edited by Liven_28

Share this post


Link to post
Share on other sites
4 hours ago, Liven_28 said:

For this I think you have to use Community framework.

You have an exemple of client-server communication on the github and maybe if you replace the "override void OnKeyPress" with an apropiate void you can send message to the server when a client is connecting (didn't try but I think something like that should works) 

 

 

 

I need to send a request from the client to the server and get a response. That is, the relationship of the 'client-server-client'

Share this post


Link to post
Share on other sites
2 hours ago, Liven_28 said:

ok, sorry I don't have more information on that.

no problem, thanks for answers

Share this post


Link to post
Share on other sites

You can go into your MissionGameplay.c and send and RPC Command when MissionGameplay is started. It would look something like this:

void MissionGameplay() {
	GetDayZGame().Event_OnRPC.Insert(OnRPC);
}

void ~MissionGameplay() {
	GetDayZGame().Event_OnRPC.Remove(OnRPC);
}

override void OnMissionStart() {
	GetGame().RPCSingleParam( NULL, MOD_RPCs.YOUR_RPC_NAME, NULL, true);
}

void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) {
	if (rpc_type == MOD_RPCs.YOUR_RPC_NAME) {
    	Param3<int, bool, string> recParam;
    	if (ctx.Read(recParam)) {
        	// Handle Client Recieve Data
        }
    }
}

Then in ServerSide you have to do something similar:

void MissionServer() {
	GetDayZGame().Event_OnRPC.Insert(OnRPC);
}

void ~MissionServer() {
	GetDayZGame().Event_OnRPC.Remove(OnRPC);
}

void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) {
	if (rpc_type == MOD_RPCs.YOUR_RPC_NAME) {
    	Param3<int, bool, string> sendParam = new Param3<int, bool, string>(0, false, "");
    	if (sender) {
        	GetGame().RPCSingleParam( NULL, MOD_RPCs.YOUR_RPC_NAME, sendParam, true, sender);
        }
    }
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 4/24/2019 at 3:29 PM, lbmaster said:

You can go into your MissionGameplay.c and send and RPC Command when MissionGameplay is started. It would look something like this:


void MissionGameplay() {
	GetDayZGame().Event_OnRPC.Insert(OnRPC);
}

void ~MissionGameplay() {
	GetDayZGame().Event_OnRPC.Remove(OnRPC);
}

override void OnMissionStart() {
	GetGame().RPCSingleParam( NULL, MOD_RPCs.YOUR_RPC_NAME, NULL, true);
}

void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) {
	if (rpc_type == MOD_RPCs.YOUR_RPC_NAME) {
    	Param3<int, bool, string> recParam;
    	if (ctx.Read(recParam)) {
        	// Handle Client Recieve Data
        }
    }
}

Then in ServerSide you have to do something similar:


void MissionServer() {
	GetDayZGame().Event_OnRPC.Insert(OnRPC);
}

void ~MissionServer() {
	GetDayZGame().Event_OnRPC.Remove(OnRPC);
}

void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx) {
	if (rpc_type == MOD_RPCs.YOUR_RPC_NAME) {
    	Param3<int, bool, string> sendParam = new Param3<int, bool, string>(0, false, "");
    	if (sender) {
        	GetGame().RPCSingleParam( NULL, MOD_RPCs.YOUR_RPC_NAME, sendParam, true, sender);
        }
    }
}

 

thanks, this work good

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×