Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player set/get cannotMove #2553

Merged
merged 12 commits into from Dec 1, 2020
Merged

Conversation

rookgaard
Copy link
Contributor

@rookgaard rookgaard commented Mar 25, 2019

Hello. I would like to present another nice functionality which went lost in 0.X series - possibility to freeze/unfreeze player. It's nice to have feature which can be used in many quests or systems like transport by wagons.

Fixes #775

src/creature.cpp Outdated Show resolved Hide resolved
@nekiro
Copy link
Member

nekiro commented Mar 26, 2019

Please don’t use _variables. Also this is really bad, because if you freeze player and he will continously spam movement it will kick him, because he will exceed the packet per second limit. (Happens because of sendCancelWalk)

@rookgaard
Copy link
Contributor Author

rookgaard commented Mar 26, 2019

@nekiro I've removed _ prefix. Anyway, what is difference between

		void setNoMove(bool _canNotMove)
		{
			cannotMove = _canNotMove;
			cancelNextWalk = true;
		}

and

		void setNoMove(bool canNotMove)
		{
			cannotMove = canNotMove;
			cancelNextWalk = true;
		}

if it's only function variable? Plus, what does this have to do with the connection limits if they apply only to packets sent by player not by server? Isn't the same situation when the player is standing at the door of the house to which he can not enter and keeps the arrow down while still receiving the message "You are not invited."?

@nekiro
Copy link
Member

nekiro commented Mar 26, 2019

Did you check if that happens before you wrote message? I'm convinced it will.

@rookgaard
Copy link
Contributor Author

@nekiro Nope, but I removed _ as you suggested. I wouldn't call myself a C++ programmer, so some of my questions may be ridiculous.

src/creature.h Outdated
@@ -408,6 +408,14 @@ class Creature : virtual public Thing
void setUseDefense(bool useDefense) {
canUseDefense = useDefense;
}
void setNoMove(bool canNotMove)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canNotMove isn't correct, cannot is a single word.

by the way, I can't find cannotMove in creature.h like you said is there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant field bool cannotMove = false;

Anyway, I've changed again function naming. How would you rate changes now?

Znote
Znote previously approved these changes Apr 1, 2019
@ranisalt
Copy link
Member

ranisalt commented Apr 2, 2019

I'd call the variable canMove, default to true and call every method get/set CanMove instead, for the sake of consistency.

@rookgaard
Copy link
Contributor Author

Ok @ranisalt, I've changed to set/get, how would you rate changes now?

@ranisalt
Copy link
Member

ranisalt commented Apr 2, 2019

LGTM, though I'd like to hear more from @nekiro point.

Copy link
Member

@nekiro nekiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to see how it behaves in-game, could you make a gif spamming move, when you are set to cannot move?

src/creature.cpp Outdated
@@ -249,6 +249,11 @@ bool Creature::getNextStep(Direction& dir, uint32_t&)

void Creature::startAutoWalk(const std::forward_list<Direction>& listDir)
{
if (getPlayer() && !getPlayer()->getCanMove()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Player* player = getPlayer();
if (player && player->getCanMove()) {

same with sendCancelWalk

void setCanMove(bool move)
{
canMove = move;
cancelNextWalk = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we set canMove to true, do we still cancelNextWalk?

Copy link
Contributor

@soul4soul soul4soul Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too was wondering about cancelNextWalk always being set to true in this function. What is the reason for the code not being this or similar

Suggested change
cancelNextWalk = true;
cancelNextWalk = !move;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still curious about this.

Copy link
Member

@Znote Znote Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is to fix desync issues mid-action, this is called to toggle the states, but no matter which direction it toggles to, you dont want to give the user half a sqm headstart as it may create odd client behavior. So even if you just got permission to walk, the character pos gets a cancel byte one last time to set the timings straight. (I might be wrong though).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Znote but if player is already movement blocked then he cannot walk, so what desynchro?

@EPuncker
Copy link
Contributor

EPuncker commented Sep 6, 2019

I would really like to see how it behaves in-game, could you make a gif spamming move, when you are set to cannot move?

I've just tested it and indeed it kicks the player because of the maxPacketsPerSecond setting

@DSpeichert
Copy link
Member

Should a player be exempt from maxPacketsPerSecond kick when they are not able to walk?

@nekiro
Copy link
Member

nekiro commented Oct 13, 2019

Should a player be exempt from maxPacketsPerSecond kick when they are not able to walk?

No, that shouldnt be done fully server side in the first place.

@DSpeichert
Copy link
Member

We can't really do it client-side, so are we merging it as-is or adding some workaround?

@EPuncker
Copy link
Contributor

closes #775 if merged

@nekiro
Copy link
Member

nekiro commented Nov 24, 2019

Do we even need it? I dont think thats something that should be in tfs repo as its mainly client sided.

@rookgaard
Copy link
Contributor Author

rookgaard commented Nov 25, 2019

Many servers still use the Cipsoft client to play, so due to the fact that it is quite difficult to edit, in my opinion it is easier to "block" it server-side.

edit: @EPuncker I've checked, that keeping arrow pushed it spams packets exactly the same way when player tries to enter house where's not invited to.

@rookgaard
Copy link
Contributor Author

@DSpeichert Is there anything else I need to change in my request?

Copy link
Member

@DSpeichert DSpeichert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at canMove and setMove, I think it would be better to use terms such as:
isMovementBlocked: true/false
setMovementBlocked: true/false

That, IMHO, is less ambiguous.

void setCanMove(bool move)
{
canMove = move;
cancelNextWalk = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still curious about this.

@andersonfaaria

This comment was marked as abuse.

@rookgaard rookgaard requested a review from nekiro June 7, 2020 23:06
@rookgaard
Copy link
Contributor Author

@DSpeichert @nekiro Can you look at it in free time? I've committed changes you requested.

@DSpeichert DSpeichert requested a review from a team June 22, 2020 07:01
src/creature.h Outdated Show resolved Hide resolved
src/luascript.cpp Outdated Show resolved Hide resolved
@EPuncker
Copy link
Contributor

EPuncker commented Oct 29, 2020

I hope we could get this merged soon, from time to time people are always requesting this function on the forum, other than the two minor code styling that I requested, everything else seems fine, I'm using this in my test server for some time already

@EPuncker EPuncker requested a review from Znote October 29, 2020 08:43
Copy link
Member

@Znote Znote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending patch to PR @rookgaard has to merge: (in his repo) rookgaard#1

void setCanMove(bool move)
{
canMove = move;
cancelNextWalk = true;
Copy link
Member

@Znote Znote Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is to fix desync issues mid-action, this is called to toggle the states, but no matter which direction it toggles to, you dont want to give the user half a sqm headstart as it may create odd client behavior. So even if you just got permission to walk, the character pos gets a cancel byte one last time to set the timings straight. (I might be wrong though).

Znote
Znote previously approved these changes Nov 6, 2020
@Znote Znote requested a review from EPuncker November 8, 2020 09:47
@Znote
Copy link
Member

Znote commented Nov 8, 2020

Do we even need it? I dont think thats something that should be in tfs repo as its mainly client sided.

Absolutely, lots of people has requested this. I also remember being rather desperate for someone to make something like this back in the day when I was hosting servers. This has been a frustration solved by uglier hacks all the time over the past 10 years.

@rookgaard
Copy link
Contributor Author

Is there anything I can do more on this PR @DSpeichert ?

Copy link
Contributor

@EPuncker EPuncker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me there is just a small request, the addition of the entries in compat.lua for it to be compatible with the old version:

getCreatureNoMove(cid)
doCreatureSetNoMove(cid, block)

@DSpeichert DSpeichert added the feature New feature or functionality label Nov 29, 2020
@rookgaard
Copy link
Contributor Author

@EPuncker I've added functions to compat.lua.

@DSpeichert DSpeichert merged commit 3b42c0e into otland:master Dec 1, 2020
@Zbizu Zbizu mentioned this pull request Dec 2, 2020
@rookgaard rookgaard deleted the feature/cannotMove branch March 17, 2021 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onMove event?
8 participants