Skip to content

GetMapDisplayName and associated core plugin changes#354

Merged
psychonic merged 1 commit intoalliedmodders:masterfrom
powerlord:findmap-plugins
Sep 17, 2015
Merged

GetMapDisplayName and associated core plugin changes#354
psychonic merged 1 commit intoalliedmodders:masterfrom
powerlord:findmap-plugins

Conversation

@powerlord
Copy link
Contributor

This replaces Pull Request #350.

This adds a new native named GetMapDisplayName.

Its purpose is to get the base name of a workshop map for display in various plugins.

At the present time, only CS:GO and TF2 actually do anything.

Its signature is

native bool GetMapDisplayName(const char[] map, char[] displayName, int maxlen);

This function returns false if a map can not be found or resolved, but true in all other circumstances (even for non-workshop maps).

No matter what it returns, displayName will always be populated, even if it is just by copying map to displayName.

The return type can be modified from its current behavior if needed. Its current behavior was me being lazy.

The changes to core plugins are to implement both GetMapDisplayName and FindMap.

The plugins updated are:

  • NextMap
  • BaseTriggers
  • BaseVotes (and basevotes/mapvote.sp)
  • MapChooser
  • Nominations
  • RockTheVote
  • RandomCycle

Note 1: In TF2, the map must be tracked or it will not resolve. This function will return false when a workshop map is asked for and FindMap returns that it is possibly available. At the present moment, TF2 workshop maps can by tracked by using the tf_workshop_map_sync command or by loading the map once.

Valve's John S. has said

In a future update we will automatically track maps found in the mapcycle, meaning you will only need tf_workshop_map_sync for maps you'd like to be prefetched but are not in the active cycle.

This change did not appear to land in the Gun Mettle Update.

@powerlord
Copy link
Contributor Author

On a side note, I still need to do some testing to make sure all plugins are displaying the proper output.

However, GetWorkshopMapBaseName has been tested on Linux TF2 and CS:GO servers by itself and it seems to be working.

These plugins were updated to switch calls to the GetFriendlyMapName stock to the GetWorkshopMapBaseName native and a variable name change here and there.

Having said that, RockTheVote's change is new and hasn't been tested at all.

@psychonic psychonic self-assigned this Jul 4, 2015
@powerlord
Copy link
Contributor Author

I did some testing on it and things seem to be working as expected.

I also merged the current master into it.

I did notice some minor naming issues I'm going to clean up, though (like *map instead of *pMapName on the C++ .h file)

Copy link
Member

Choose a reason for hiding this comment

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

Nit: &szTmp[9] syntax would be preferred over szTmp + 9.

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 was using szTmp[9] before and Clang complained about it. Didn't try it with a & though.

@psychonic
Copy link
Member

The basics of this look okay to me, but I only skimmed through the mapchooser+friends edits.

If it's all tested, we should be good. My biggest concern there would be to make sure that we're still storing the full map "name" for votes, nominations, etc. rather than the new base name, as a base could potentially be ambiguous and should only be used for display.

@powerlord
Copy link
Contributor Author

@psychonic As you said, the base name is for display only. Generally, we create a variable for it, retrieve it, display it (or add it to a menu in the display name field), then let it go out of scope.

Having said that, the name returned from FindMap (not GetWorkshopMapBaseName) may be stored in adt_arrays. Luckily, FindMap is safe to call on map names returned from FindMap, so that should be a non-issue.

@asherkin
Copy link
Member

asherkin commented Jul 8, 2015

Can we go for just GetMapBaseName (or GetMapDisplayName) instead?

@powerlord
Copy link
Contributor Author

@asherkin I'm not particularly attached to the function name, so we can change it.

Should we just go with GetMapDisplayName then? It probably describes the function's purpose better than GetMapBaseName.

@asherkin
Copy link
Member

asherkin commented Jul 8, 2015

GetMapDisplayName sounds good to me, @psychonic?

@powerlord
Copy link
Contributor Author

I'm going to push this for now so I don't forget. If @psychonic doesn't like the name, we can always change it again later.

@powerlord
Copy link
Contributor Author

@asherkin @psychonic One question.

I've noticed that in some plugins I've updated LogAction to display the display name and some I didn't.

Since this behavior should be the same across plugins, should we be displaying the display name or the original map name in LogAction?

I ask because I'm not sure which we should use due to OnLogAction's existence.

@psychonic
Copy link
Member

GetMapDisplayName sounds good to me, @psychonic?

Yeah, that's fine.

@psychonic
Copy link
Member

@powerlord I think that logs should give the full map name or path, which display to users such as in chat or menus should use the shortened display name. @asherkin thoughts?

@powerlord
Copy link
Contributor Author

Hmm, should I update the documentation for GetMapDisplayName to note that it will return the result of FindMap for non-workshop maps?

Edit: Derp, of course I should.

@powerlord
Copy link
Contributor Author

@psychonic @asherkin Right now, GetMapDisplayName returns true if FindMap returns FindMap_Found, FindMap_FuzzyMatch, or FindMap_NonCanonical. Should I update it to only return true if the displayName is different than the map name passed in?

@powerlord powerlord changed the title GetWorkshopMapBaseName and associated core plugin changes GetMapDisplayName and associated core plugin changes Jul 9, 2015
@powerlord
Copy link
Contributor Author

Yeah, I heard of an issue with snprintf on Windows, so I removed some of what I think is redundant logic (now that we overwrite the . with \0) that should lessen the chance of it happening.

Needs testing, of course.

Still, make sure you pass PLATFORM_MAX_PATH for the nMapNameMax variable and it won't ever happen.

@powerlord
Copy link
Contributor Author

The previous change has been tested as working on Linux, don't have a Windows server to test it, but it should work.

test_mapdisplayname workshop/454141042
GetMapDisplayName says "cp_kakariko_b1" for "workshop/454141042"

@powerlord
Copy link
Contributor Author

I ran into a new issue, though.

If you sync a lot of maps in server.cfg, the game server may not have them all cached by the time it generates the nominate list or voting list during the first map, which is done in OnConfigsExecuted.

Should we delay creating these menus/votes until the first time we use them in a map?

@powerlord
Copy link
Contributor Author

The previous changes dealing with late loading the nominations list and list of maps for the next vote appear to be working.

To clarify, the map list is not being late loaded, only the arrays and menus that use it are, in order to do late name resolution on them.

@powerlord
Copy link
Contributor Author

I'm kinda glad this hadn't been merged yet, as I just spotted a bug in the CS:GO code for GetMapDisplayName... when I fixed the pointer math to array syntax in commit 14d62b0, I used the wrong array.

@psychonic
Copy link
Member

Sorry that I haven't had a chance to finish reviewing it. It's been a busy past few weeks,

@powerlord
Copy link
Contributor Author

I just force reset back a commit. Turns out the sourcepawn commit referenced in sourcemod-git5533 is very buggy.

Edit: Ugh, the previous master merge has the same exact issue.

Ended up rolling back the previous pull from master and redoing the GetMapDisplayName regression fix.

@powerlord
Copy link
Contributor Author

I'm not sure why, but TF2's FindMap seems to no longer resolve workshop map names like it used to.

For example, immediately after seeing this in the log (because I did tf_workshop_map_sync):

[TF Workshop] Got updated information for map [ workshop/cp_glassworks_rc6a.ugc454118349 ]

this happens

test_findmap workshop/454118349
FindMap says PossiblyAvailab - "workshop/454118349"

It used to return NonCanonical and copy the longer map name into the map variable.

Short names are still resolved, such as cp_dust to cp_dustbowl.

@powerlord
Copy link
Contributor Author

I emailed Valve's John Schoenick about this issue. His response:

FindMap does not return Found unless it has the map fully downloaded and available -- the message in question just means we have full information about the map, not that it is installed. I'll tweak it in the next update so that it still provides the full name, if known, in that situation, but otherwise this is working as intended.

I have replied to John pointing out the following:

  1. The test I performed was 10 hours after the tf_workshop_map_sync command was initially issued, although it was issued again on map change.
  2. The map in question is the same map I've had on my server since I initially started testing FindMap a week or so after Workshop support was added. It was updated once since then.
  3. FindMap used to return eFindMap_NonCanonical and update the map name for maps that were already on the server.

He hasn't responded to that yet, though.

@powerlord
Copy link
Contributor Author

The above behavior I'm seeing is a bug:

Can you switch to this level with changelevel ? There is a bug in the currently release build that could cause UGC files to never finish downloading. We hope to have a fix for that soon, but it would be good to rule that out.

After doing more testing, I can't switch to workshop maps, even ones that are completely downloaded... it just tries to re-download them and the server soft-hangs (i.e. the console still works, but no commands are processed). When I sent John my logs, he said:

That sounds like the aforementioned bug, which will be fixed by the next TF update. That would explain why FindMap() never considered it available as well :-/

@powerlord
Copy link
Contributor Author

Looks like today's TF2 update should fix the issues mentioned in the previous posts. Needs testing still, though.

@powerlord
Copy link
Contributor Author

Did some testing after today's update.

All Map Workshop functionality appears to be working as intended.

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 not sure you need this local array, it looks like you copy from it regardless to pDisplayname regardless of return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pMapName is const and FindMap can (and does) modify its first argument.

Copy link
Member

Choose a reason for hiding this comment

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

That's unfortunately correct.

However, you have a nice array already present for you, via pDisplayname. If this is fed into FindMap you shouldn't have this issue. I can see the pain in pawn though.

core/HalfLife2.h Outdated
Copy link
Member

Choose a reason for hiding this comment

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

should probably be a size_t for the length of your string buffer, but the line above it also has an int so I won't fault you for it.

@KyleSanderson
Copy link
Member

The engine at the moment in FindMap will write out 100 characters to an internal buffer then do the scan.

If you pass a length of 0, you can pass your const's in there and they should come out clean. This should avoid having to copy your buffer over and over. I'm really mixed on breaking this API in pawn and explicitly getting you guys to pass a const in instead of the following

char dispMap[24];
strncopy(dispMap, sizeof(dispMap), map);
new SMMapResult res = FindMap(dispMap, sizeof(dispMap);

I find this pattern to be really harmful in pawn, we have nothing else like it and it seems really bogus. In core at the moment we have IsMapValid creating a bogus temporary buffer to use the valve api.

@powerlord
Copy link
Contributor Author

@KyleSanderson Last time I checked, attempting to pass a const char[] to a method that takes a char[] will get you a compiler error in both SourcePawn and C++.

@KyleSanderson
Copy link
Member

#396

@powerlord
Copy link
Contributor Author

Current build won't compile the plugins, but after fighting git for the last 20 minutes before finally convincing it that the submodule versions really did change (it kept claiming they were up to date on the old versions), I'm going to do a "safety save."

@KyleSanderson
Copy link
Member

@powerlord you now have 21 commits in this branch and it's two months old, you should most likely rebase it once you have everything working.

@powerlord
Copy link
Contributor Author

@KyleSanderson Question about that... since I've merged master into this several times, do I just select all the commits and combine them? I ask because all the commits made to master also show up in the commit log for this branch.

@powerlord
Copy link
Contributor Author

@KyleSanderson

There, I think I rebased this correctly. I had to watch it as it told me every time I changed HalfLife2.cpp that there was a conflict, but there was one instance where my change was the correct one (It was the one where the command name changed from GetWorkshopMapBaseName to GetMapDisplayName).

It compiled using AMBuild on Windows at any rate.

This function will resolve the name of a map using FindMap, then (if applicable), will turn a workshop map name into a nicely formatted name.

Currently only TF2 and CS:GO Map Workshops are supported.  More can be added at a later date.

This function returns false if a map was not found, but true in any other instance even if FindMap could not resolve the map name.

This patch also updates the following core plugins to use this GetMapDisplayName:

BaseTriggers
BaseVotes
MapChooser
NextMap
Nominations
RandomCycle
RockTheVote
@powerlord
Copy link
Contributor Author

I've amended the commit message as it was a mess after the rebase earlier.

psychonic added a commit that referenced this pull request Sep 17, 2015
GetMapDisplayName and associated core plugin changes.
@psychonic psychonic merged commit c982cc9 into alliedmodders:master Sep 17, 2015
@psychonic
Copy link
Member

Let's get this into the dev branch. We can iterate on it from there if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants