Author Topic: Feature: Player Search Function in Serverbrowser  (Read 20853 times)

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Player Search Function in Serverbrowser
« Reply #20 on: February 06, 2014, 09:38:11 AM »
Thanks for the contribution, xrichardx!  I'll try to take a look at it when I get home.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #21 on: February 06, 2014, 10:58:58 AM »
I've just extended the dialog callback function. It now also selects the server the player is playing on when you click on a result:

Code: [Select]
//Edit by Richard
//Message handler for Player Search Dialog
static LRESULT CALLBACK SearchPlayerDlg (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDC_SP_EDIT, EN_CHANGE), (LPARAM) GetDlgItem(hDlg, IDC_SP_EDIT));
return TRUE;


case WM_COMMAND:
static std::vector <std::pair<std::string, int> > vFound;

if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}

if ((LOWORD(wParam) == IDC_SP_EDIT) and (HIWORD(wParam) == EN_CHANGE))
{
std::string sContentBuffer;
char szNameBuffer[GetWindowTextLength(GetDlgItem(hDlg, IDC_SP_EDIT)) + 1];

SendMessage(GetDlgItem(hDlg, IDC_SP_LIST), LB_RESETCONTENT, 0, 0);

GetWindowText(GetDlgItem(hDlg, IDC_SP_EDIT), szNameBuffer,
sizeof(szNameBuffer) / sizeof (szNameBuffer[0]));
SearchPlayer(szNameBuffer, &vFound);
for (int i = 0; i < vFound.size(); i++)
{
sContentBuffer.assign(g_mServers[vFound[i].first].vPlayers[vFound[i].second].sName);
sContentBuffer.append (" on ");
sContentBuffer.append (g_mServers[vFound[i].first].sHostName);
int index = SendMessage(GetDlgItem(hDlg, IDC_SP_LIST), LB_ADDSTRING,
0, (LPARAM) sContentBuffer.c_str());
SendMessage(GetDlgItem(hDlg, IDC_SP_LIST), LB_SETITEMDATA, index, i);
}
}

if (HIWORD(wParam) == LBN_SELCHANGE and LOWORD(wParam) == IDC_SP_LIST)
{
int iFoundIndex;
int iListId;

iFoundIndex = SendMessage(GetDlgItem(hDlg, IDC_SP_LIST),
LB_GETITEMDATA,
SendMessage (GetDlgItem(hDlg, IDC_SP_LIST), LB_GETCURSEL, 0, 0),
0);
iListId = GetListIDFromAddress(vFound[iFoundIndex].first.c_str());
if (iListId >= 0)
{
SetFocus(g_hServerList);
ListView_SetItemState(g_hServerList, -1, 0, 0x000F);
ListView_SetItemState(g_hServerList, iListId, LVIS_FOCUSED | LVIS_SELECTED, 0x000F);

UpdateInfoLists(iListId, false);
//TODO: set scrollbar position
}
return TRUE;
}
break;
}

    return FALSE;
}

I'll add source, the executable and a cvs patch containing all changes.

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: Feature: Player Search Function in Serverbrowser
« Reply #22 on: February 06, 2014, 03:00:05 PM »
I can not find a SVN repository... Do you mean CSV? http://paintball2.cvs.sourceforge.net/viewvc/paintball2/serverbrowser/
Well, here's the patch, created with TortoiseCSV. It also contains some changes where i didn't change anything because my IDE trims spaces at the end of a line.
Let it be CSV, github or anything else. It doesn't really matter.

My question is: do you really need something like an asterisk that matches every string? I mean, when i open up the dialog right now and want to check if a player with the name "payl" is playing,
just entering "p"      gives 9 results
just entering "pa"   gives 1 result
and entering "pay"   gives 0 results
So who would use such a feature?
I use it, because I sometimes don't want to update my friend list every time some noob changes clan so I do "*nick" and it will only match end that has "nick", it can help if people have short name that can be in another nick. Another reason I used it was that my player search can only find one people at time, so having false positives was not nice.
It just helps if you are not sure about nick, i.e. you know you had noname with number ending with 0: noname???0 .
So I do "need" it in way I use it (no multiple results and friend list based on that). But for now here it isn't that important, it depends which way you go with it.

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Player Search Function in Serverbrowser
« Reply #23 on: February 07, 2014, 08:54:36 PM »
Hm, for some reason the patch did not want to apply:

Quote
$ patch -i serverbrowser.patch
(Stripping trailing CRs from patch; use --binary to disable.)
patching file resource.h
Hunk #1 FAILED at 31 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file resource.h.rej
(Stripping trailing CRs from patch; use --binary to disable.)
patching file serverbrowser.cpp
Hunk #1 FAILED at 8 (different line endings).
Hunk #2 FAILED at 591 (different line endings).
2 out of 2 hunks FAILED -- saving rejects to file serverbrowser.cpp.rej
(Stripping trailing CRs from patch; use --binary to disable.)
patching file serverbrowser.h
Hunk #1 FAILED at 8 (different line endings).
Hunk #2 FAILED at 42 (different line endings).
2 out of 2 hunks FAILED -- saving rejects to file serverbrowser.h.rej
(Stripping trailing CRs from patch; use --binary to disable.)
patching file serverbrowser.rc
Hunk #1 FAILED at 14 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file serverbrowser.rc.rej
(Stripping trailing CRs from patch; use --binary to disable.)
patching file serverbrowserGUI.cpp
Hunk #1 FAILED at 8 (different line endings).
Hunk #2 FAILED at 17 (different line endings).
Hunk #3 FAILED at 58 (different line endings).
Hunk #4 FAILED at 134 (different line endings).
Hunk #5 FAILED at 161 (different line endings).
Hunk #6 FAILED at 193 (different line endings).
Hunk #7 FAILED at 233 (different line endings).
Hunk #8 FAILED at 458 (different line endings).
Hunk #9 FAILED at 631 (different line endings).
Hunk #10 FAILED at 688 (different line endings).
Hunk #11 FAILED at 959 (different line endings).
Hunk #12 FAILED at 1070 (different line endings).
Hunk #13 FAILED at 1081 (different line endings).
Hunk #14 FAILED at 1179 (different line endings).
14 out of 14 hunks FAILED -- saving rejects to file serverbrowserGUI.cpp.rej

I guess you changed the line endings in the files?

Edit: nevermind, had to use --binary as a parameter.

Edit 2: um... this doesn't compile.

if ((LOWORD(wParam) == IDC_SP_EDIT) and (HIWORD(wParam) == EN_CHANGE)) <=- what is "and"?
char szNameBuffer[GetWindowTextLength(GetDlgItem(hDlg, IDC_SP_EDIT)) + 1]; <=- not constant

Edit 3: Made some minor changes and got it compiling... your compiler is strange...

Edit 4: Submitted changes to repository and put new build in folder to be included with the next build package (it's only ~4k larger, so the size difference you saw must have just been compiler related).
« Last Edit: February 07, 2014, 09:35:00 PM by jitspoe »

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #24 on: February 08, 2014, 06:59:04 AM »
Edit 2: um... this doesn't compile.

if ((LOWORD(wParam) == IDC_SP_EDIT) and (HIWORD(wParam) == EN_CHANGE)) <=- what is "and"?
char szNameBuffer[GetWindowTextLength(GetDlgItem(hDlg, IDC_SP_EDIT)) + 1]; <=- not constant

Edit 3: Made some minor changes and got it compiling... your compiler is strange...

Edit 4: Submitted changes to repository and put new build in folder to be included with the next build package (it's only ~4k larger, so the size difference you saw must have just been compiler related).

"and" should be the written alternative to "&&". AFAIK it should also be part of the standard:
http://en.cppreference.com/w/cpp/keyword/and
If it doesn't work with the MS compiler then I'm sorry for the inconvenience.

Initializing arrays to a variable size is indeed a speacial "feature" of the GNU Compiler Collection c++ compiler - I did not know that. Also here, I'm sorry for the inconvenience. I did this because I don't like having the risk of buffer overflows like you do have when you just initialize it to 256. Probably a vector of chars should then be used there:

std::vector vNameBuffer(GetWindowTextLength(GetDlgItem(hDlg, IDC_SP_EDIT))[/color] + 1);
and "&vNameBuffer[0]" should be used to pass it to any function that wants a char pointer to write at.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #25 on: February 08, 2014, 07:55:28 AM »
Doublepost:
Inspired by T3RR0R15T i've done a few more improvements:

1. When the dialog is opened, the initial focus is now already on the edit control
2. An Update button was added which will reload all players on all servers and re-do the search.
3. When no player was found, this information will be displayed in the listbox instead of nothing.

Also, i've put the dialog and all other resources in the correct, language neutral area in the resource file. Adding it directly at the header was only a temporary solution.
T3RR0R15T is right now collecting translations of the dialog so hopefully we have correct translations for all languages soon. AFAIK he still needs translations for the French and Slovakian language.

/Edit: The update button is not working the way it should right now as a function call of "UpdateList" does not block the program until the local variables are really updated. So, the search is re-done on the local saved players before the pb2 servers actually have answered and the players in the local variabled have been updated. So right now, the Update button has to be pressed twice in order to really update the content. Any ideas about how to solve this?
My ideas:
1. wait for the WaitThread to receive all answer - possible problem: Sometimes there are IPs without a running server on the serverlist and they would not send an answer.
2. have a fixed time to wait after calling "UpdateList" but before the search is done - possible problem: not as fast as it could be, users would have to wait for their list to be updated and it might feel unresponsive.
3. combination of 1 and 2: problem: the program would often wait for the whole timeout if there are any offline ips on the local serverlist. This may feel unresponsive, so same problems as 2.
4. 2 different buttons: One for refreshing the serverlist and one for redoing the local search. Problem: This might confuse users.
5. No buttons at all and just an auto-update-interval. Problem: Servers may be spammed.


« Last Edit: February 08, 2014, 09:11:11 AM by xrichardx »

T3RR0R15T

  • Map Committee
  • Autococker
  • Posts: 2593
Re: Feature: Player Search Function in Serverbrowser
« Reply #26 on: February 08, 2014, 09:59:21 AM »
I've added the patch above and some menu changes to the cvs.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #27 on: February 08, 2014, 03:18:11 PM »
In order to make the update button work better a made a few improvements. If not starts reloading the players on all servers, waits one seconds in an extra thread while replacing the update button's text with dots so the user knows that something is going on and then does the search. Also, it tries to keep the same player selected if possible (means: if he did not disconnect).
It's posssible that there are some problems regarding the casting of the argument-structure (args). The GNU compiler does fine, but I don't know about MS's compiler. If it throws any errors then I don't want to occupy anyone's (jitspoe's or T3RR0R15T's) time, simply tell me and I will download and install Microsofts compiler in order to fix this myself. Edit: T3RR0R15T confirmed that VC++ 2012 does compile this.
« Last Edit: February 08, 2014, 06:42:27 PM by xrichardx »

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Player Search Function in Serverbrowser
« Reply #28 on: February 08, 2014, 03:44:27 PM »
Interesting that this is the first time I've heard of the and/or keyword operators.  Seems they're almost never used but were there to support old keyboards without &, |, ^, etc. symbols.  Took me a while just to find a page that explained that: http://stackoverflow.com/questions/2376448/the-written-versions-of-the-logical-operators

Do you have a sourceforge.net account?  It would probably be easiest to just give you direct CVS access so you can submit your changes directly without making patches.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #29 on: February 08, 2014, 03:54:54 PM »
I just sent you a PM with my account detail.

Edit: Which compiler are you using right now? Visual Studio 2008?
« Last Edit: February 08, 2014, 04:21:07 PM by xrichardx »

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: Feature: Player Search Function in Serverbrowser
« Reply #30 on: February 08, 2014, 04:06:38 PM »
Interesting that this is the first time I've heard of the and/or keyword operators.
Well jitspoe, you surely never heard of any other language than C/C++...
Almost all modern languages support and/or/not, even those whose were firstly implementing C-style (i.e. PHP). Seems like C++ went same way.

Quote
The GNU compiler does fine, but I don't know about MS's compiler.
That's why C++ suck, there is no standard whatsoever, and both MS and GCC tries to be cool by adding some weird stuff that will break more older code, by i.e. removing old stuff... take this as an example: http://stackoverflow.com/questions/3437410/c-extension-and-operators , did you know of that operator jitspoe?

T3RR0R15T

  • Map Committee
  • Autococker
  • Posts: 2593
Re: Feature: Player Search Function in Serverbrowser
« Reply #31 on: February 08, 2014, 04:52:06 PM »
Edit: Which compiler are you using right now? Visual Studio 2008?
Should be Visual Studio 2010, if he doesn't changed it. I use Visual Studio 2012 Express.

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Player Search Function in Serverbrowser
« Reply #32 on: February 08, 2014, 07:54:07 PM »
I'm still using VS 2008 express.  It seems things get more bloated and less compatible with each new version, so I'm staying old school! :)

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #33 on: February 08, 2014, 07:58:23 PM »
I'm still using VS 2008 express.  It seems things get more bloated and less compatible with each new version, so I'm staying old school! :)
Alright, thank you.

Edit: Updated "serverbrowserGUI.cpp":
- I made searching delayed after pinging the servers.
- I also added the LVS_SHOWSELALWAYS style to g_hServerList because when the main program loses focus the other list views will keep their content, so the selected server should still be visible. Also, it improves how the program behaves when using dialogs.
« Last Edit: February 09, 2014, 07:15:37 AM by xrichardx »

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Player Search Function in Serverbrowser
« Reply #34 on: February 09, 2014, 05:06:32 PM »
Cool.

Some other suggestions:

- Don't show list of servers when nothing is typed in.
- ESC could close the search window.

T3RR0R15T

  • Map Committee
  • Autococker
  • Posts: 2593
Re: Feature: Player Search Function in Serverbrowser
« Reply #35 on: February 09, 2014, 05:24:39 PM »
- Don't show list of servers when nothing is typed in.

I like it to see everything if the search field is empty :P

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Player Search Function in Serverbrowser
« Reply #36 on: February 09, 2014, 05:45:55 PM »
I like it to see everything if the search field is empty :P
What's the point of using the search then?  You can see everything without opening the search window. :)

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #37 on: February 10, 2014, 08:27:03 AM »
In my opinion, the dialog is something like a playerlist with a filter function. It should simply apply that filter to the players and only display players that match - so when the filter is empty, all players match because they are not filtered.
Also, when you open it and it displays all players you have the advantage that you can see all players listed by alphabet in one place and simply go through them to maybe search for a player you know and would like to play with without knowing who exactly you are searching for. In the main window you had to go through all servers in order to do that, which is not as easy as going just through one list.
Actually, I've manually made it find all players when no filter is applied (std::string::find will not match empty strings) because I thought that displaying some information some users might not need or want is a better solution that not displaying information that some players would like to see. The users who do not like to see that information could easily ignore it while the users wanting that information could not just imagine it theirselves.

I will implement some hotkeys like F5 to refresh the search and esc to close the dialog.

Edit: Hotkeys Return and Escape work now.

Edit2:
- F5 update hotkey added
- made dialog resizable
- structured callback function a lot better by splitting up the one callback function into sub functions like OnSearchPlayerDlgUpdate
I'm thinking about turning the ListBox into a ListView because I think it would look a lot better and make the playername more easy to distinguish between playername and servername.
« Last Edit: February 10, 2014, 03:07:32 PM by xrichardx »

T3RR0R15T

  • Map Committee
  • Autococker
  • Posts: 2593
Re: Feature: Player Search Function in Serverbrowser
« Reply #38 on: February 11, 2014, 09:31:53 AM »
There is an update each time i type or remove a character in the search box now. Is that right?

xrichardx

  • 68 Carbine
  • Posts: 295
Re: Feature: Player Search Function in Serverbrowser
« Reply #39 on: February 11, 2014, 11:51:58 AM »
There is an update each time i type or remove a character in the search box now. Is that right?
Yes, fixed it.

Edit: Also made the dialog use a listview control instead of a listbox, so the player's name and the server's name are easier to distinguish between now. There might be some translation problems because I used google translator for translating "player" and "on server". The german dialog now looks this way:

« Last Edit: March 07, 2014, 09:32:52 PM by xrichardx »