UE2 - UT2kX Communicate from client to server

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
How to send key input to the server (Was: Communicate from client to server)

All right. I noticed that the base of my problem is that I don't know how to send key input from client to server.

Are there some examples, that could be read for this?

I've found some posts on this forum, but there were rather old and for UT2003. It didn't work.

So how to communicate key input from Client to Server? Do I need an Interaction class? Where I will put my function handling key input on the server? And where will be the function handling client input on client?
I was playing with this yesterday for 4 hours and didn't get any result... :-/ I was able to detect key input all the time just on the client side... :-/

My goal is to change the state of the game on the server (move to the custom state), when the player press certain key.

Thx a lot for any help or information!

SK
 
Last edited:

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
Problem probably solved

I have overlooked two great topics about replication on UnrealWiki. Namely:

http://wiki.beyondunreal.com/wiki/Replication_De-Obfuscation

with a lot of general info about replication and how it works.

and

http://wiki.beyondunreal.com/wiki/Another_Look_At_Replication

with an example that should solve my problem. I will try to make it work in several days and then I'll post my code here and if it worked. Hope this thread will at least help to summarize information about this topic (client - server communication)...

SK
 

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
Conclusion

At last I was able to make what I wanted. The bug was I was editing code, which I was not using (I used different package) LOL! Anyway, here is working key-detecting code:

First you need to create an interaction class for your player. You can do this with mutator and some examples are on unrealwiki.

Interaction class:
Code:
class AVCR_Interaction extends Interaction;

function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
{
	log("We are in keypressed");
    if ((Action == IST_Press) && (Key == IK_Home))
    {
		AVCRxPlayer(ViewportOwner.Actor).KeyPressed();
	}

	if ((Action == IST_Press) && (Key == IK_Space))
    {

	}

    if ((Action == IST_Press) && (Key == IK_PageDown))
    {
        AVCRxPlayer(ViewportOwner.Actor).SpeedDecreased();
    }

    if ((Action == IST_Press) && (Key == IK_PageUp))
    {
    	AVCRxPlayer(ViewportOwner.Actor).SpeedIncreased();
	}

    return false;
}



defaultproperties
{
	bActive = true
	bVisible = true
}

Then in your custom player controller class you need to have this:
Code:
class AVCRxPlayer extends xPlayer;

replication
{
	reliable if ( Role<ROLE_Authority )
		NotifyServer, bExperimentKeyPressed, SpeedIncreased, SpeedDecreased;
}

simulated function KeyPressed()
{
	log("We are in KeyPressed function");
	bExperimentKeyPressed = true;
	NotifyServer();

}

function NotifyServer()
{
	log("We are in NotifyServer");
	if (AVCR_Experiment(Level.Game).IsInState('ExperimentRunning'))
	{
    	AVCR_Experiment(Level.Game).gotoState('ExperimentEnd');
	}
	else
	    AVCR_Experiment(Level.Game).gotoState('ExperimentStart','Begin');
}

function SpeedIncreased()
{
	log("We are in SpeedIncreased");
	if (Pawn != none)
	{
		if (Pawn.GroundSpeed <= 1.8 * Pawn.Default.GroundSpeed)
			Pawn.GroundSpeed += 0.2 * Pawn.Default.GroundSpeed;
	}


}

function SpeedDecreased()
{
	log("We are in SpeedDecreased");
	if (Pawn != none)
	{
		if (Pawn.GroundSpeed > 0.3 * Pawn.Default.GroundSpeed)
			Pawn.GroundSpeed -= 0.2 * Pawn.Default.GroundSpeed;
	}
}

Thats pretty much it. This code is making your bot speed up and speed down (by pressing PageUp/Down keys) and it is switching the states of the game when the Home key is pressed (the code of the new gametype is not interesting, so I havent put it here).