]> icculus.org git repositories - divverent/nexuiz.git/blob - data/oldmenuqc/custom/joingame.qm
Merge first change into the branch.
[divverent/nexuiz.git] / data / oldmenuqc / custom / joingame.qm
1 // Property of Alientrap
2 // custom/joingame.qm
3
4 // stepValue should contain the field name
5 void() Nex_Action_JoinGame_SortBy_Action =
6 {
7         if( HostCache_SortField == self._realValue )
8                 sethostcachesort( self._realValue, !HostCache_SortDescending );
9         else
10                 sethostcachesort( self._realValue, true );
11         HostCache_ResortViewSet();
12 };
13
14 void() Nex_Action_JoinGame_SortBy =
15 {
16         self._realValue = gethostcacheindexforkey( self.target );
17         self.action = Nex_Action_JoinGame_SortBy_Action;
18 };
19
20 void() Nex_Automation_CreateEntries =
21 {
22         local entity lTemplate;
23         local float  lCounter;
24
25         lTemplate = Menu_GetItem( "Entry" );
26         for( lCounter = 0 ; lCounter < 64 ; ++lCounter ) {
27                 local entity lEntry;
28
29                 lEntry = Menu_DeriveItem( lTemplate, strcat( "Entry", ftos( lCounter) ),  self.parent, true );
30                 lEntry.stepValue = lCounter;
31         }
32         Menu_LinkItem( self._parent );
33 };
34
35 void() Nex_Action_EntryConnect =
36 {
37         cmd( "connect \"", gethostcachestring( SLIST_FIELD_CNAME, self.stepValue ), "\"\n" );
38
39         m_hide();
40 };
41
42 void() Nex_Action_RefreshSlist =
43 {
44         HostCache_RefreshHostCache();
45 };
46
47 void() Nex_Action_JumpToPlayerSetup;
48 void() Nex_Action_JumpToJoinGame =
49 {
50         local entity lItem;
51
52         if(cvar_string("_cl_name") == "Player")
53         {
54         Nex_Action_JumpToPlayerSetup();
55         return;
56         }
57
58         resethostcachemasks();
59         sethostcachesort( SLIST_FIELD_PING, false );
60         HostCache_RefreshHostCache();
61
62         lItem = Menu_GetItem( "Normal::Panel" );
63         String_EntitySet( lItem, link, "JoinGame" );
64
65         Raise_Update( lItem );
66         Menu_UpdateRunFlags();
67         Menu_JumpToWindow( lItem._link, false, false );
68 };
69
70 // mask parser
71 /* query string format:
72    two types:
73 1) Prefix "mask" Advanced query
74         Format: ( and|or TYPE OP MASK [...] )*
75         TYPE :  one of the slist fields
76         OP:
77                 <;<=;>=;==;!= normal arithmetic comparison operators (default <=) (= instead of == also supported)
78                 $$ 'does contain' (default string op)
79                 !$ 'does not contain'
80                 : leads to default op
81
82         On every occurence of AND or OR a new mask of the spec type is created.
83         E.g. or name: "WWClan" ping: 200 and protocol == 3 maxplayers > 5
84         will create an or and an and mask
85 2) No prefix:
86         keyword *
87
88         notempty
89         compatible      (same net protocol version)
90         goodping        (ping <= 150)
91         mediumping      (ping <= 250)
92 */
93 #define GetNextToken    if( ++lTokenNum > lTokenCount ) goto finish; else lToken = argv( lTokenNum )
94 void() Nex_Action_ExecuteQuery =
95 {
96         local float lAndPos, lOrPos;
97         local float lTokenNum, lTokenCount;
98
99         resethostcachemasks();
100         lAndPos = SLIST_MASK_AND;
101         lOrPos = SLIST_MASK_OR;
102
103         lTokenCount = tokenize( self._target.value );
104
105         for( lTokenNum = 0 ; lTokenNum < lTokenCount ; ++lTokenNum ) {
106                 local string lToken;
107                 lToken = argv( lTokenNum );
108
109                 if( lToken == "notempty" ) {
110                         sethostcachemasknumber( lAndPos, SLIST_FIELD_NUMPLAYERS, 0, SLIST_TEST_NOTEQUAL );
111                         ++lAndPos;
112                 } else if( lToken == "compatible" ) {
113                         sethostcachemasknumber( lAndPos, SLIST_FIELD_PROTOCOL, NET_CURRENTPROTOCOL, SLIST_TEST_EQUAL );
114                         ++lAndPos;
115                 } else if( lToken == "goodping" ) {
116                         sethostcachemasknumber( lAndPos, SLIST_FIELD_PING, 150, SLIST_TEST_LESSEQUAL );
117                         ++lAndPos;
118                 } else if( lToken == "mediumping" ) {
119                         sethostcachemasknumber( lAndPos, SLIST_FIELD_PING, 250, SLIST_TEST_LESSEQUAL );
120                         ++lAndPos;
121                 } else if( lToken == "mask" ) {
122                         // start the query loop
123                         GetNextToken;
124                         while( 1 ) {
125                                 local bool lAndMask;
126
127                                 if( lToken == "or" )
128                                         lAndMask = false;
129                                 else if( lToken == "and" )
130                                         lAndMask = true;
131                                 else
132                                         goto finish; // abort the parsing
133                                 // now parse all condition fields
134                                 while( 1 ) {
135                                         local float lField;
136                                         local float lOperator;
137                                         local bool  lIsStringArg;
138
139                                         GetNextToken;
140                                         // now get the field number
141                                         if( lToken == "cname" ) {
142                                                 lField = SLIST_FIELD_CNAME;
143                                                 lIsStringArg = true;
144                                         }
145                                         else if( lToken == "ping" ) {
146                                                 lField = SLIST_FIELD_PING;
147                                                 lIsStringArg = false;
148                                         }
149                                         else if( lToken == "game" ) {
150                                                 lField = SLIST_FIELD_GAME;
151                                                 lIsStringArg = true;
152                                         }
153                                         else if( lToken == "mod" ) {
154                                                 lField = SLIST_FIELD_MOD;
155                                                 lIsStringArg = true;
156                                         }
157                                         else if( lToken == "map" ) {
158                                                 lField = SLIST_FIELD_MAP;
159                                                 lIsStringArg = true;
160                                         }
161                                         else if( lToken == "name" ) {
162                                                 lField = SLIST_FIELD_NAME;
163                                                 lIsStringArg = true;
164                                         }
165                                         else if( lToken == "maxplayers" ) {
166                                                 lField = SLIST_FIELD_MAXPLAYERS;
167                                                 lIsStringArg = false;
168                                         }
169                                         else if( lToken == "numplayers" ) {
170                                                 lField = SLIST_FIELD_NUMPLAYERS;
171                                                 lIsStringArg = false;
172                                         }
173                                         else if( lToken == "protocol" ) {
174                                                 lField = SLIST_FIELD_PROTOCOL;
175                                                 lIsStringArg = false;
176                                         }
177                                         else
178                                         { // increment the mask pos and let upper check for or or and
179                                                 if( lAndMask )
180                                                         ++lAndPos;
181                                                 else
182                                                         ++lOrPos;
183                                                 break;
184                                         }
185                                         // now lets determine the comparison operator
186                                         GetNextToken;
187                                         if( lToken == "$$" )
188                                                 lOperator = SLIST_TEST_CONTAINS;
189                                         else if( lToken == "!$" )
190                                                 lOperator = SLIST_TEST_NOTCONTAIN;
191                                         else if( lToken == "<" )
192                                                 lOperator = SLIST_TEST_LESS;
193                                         else if( lToken == "<=" )
194                                                 lOperator = SLIST_TEST_LESSEQUAL;
195                                         else if( lToken == "==" || lToken == "=" )
196                                                 lOperator = SLIST_TEST_EQUAL;
197                                         else if( lToken == ">" )
198                                                 lOperator = SLIST_TEST_GREATER;
199                                         else if( lToken == ">=" )
200                                                 lOperator = SLIST_TEST_GREATEREQUAL;
201                                         else if( lToken == "!=" )
202                                                 lOperator = SLIST_TEST_NOTEQUAL;
203                                         else if( lToken == ":" )
204                                                 if( lIsStringArg )
205                                                         lOperator = SLIST_TEST_CONTAINS;
206                                                 else
207                                                         lOperator = SLIST_TEST_LESSEQUAL;
208                                         else
209                                                 goto finish; // abort the parsing
210
211                                         GetNextToken;
212                                         if( lIsStringArg )
213                                                 if( lAndMask )
214                                                         sethostcachemaskstring( lAndPos, lField, lToken, lOperator );
215                                                 else
216                                                         sethostcachemaskstring( lOrPos, lField, lToken, lOperator );
217                                         else
218                                                 if( lAndMask )
219                                                         sethostcachemasknumber( lAndPos, lField, stof( lToken ), lOperator );
220                                                 else
221                                                         sethostcachemasknumber( lOrPos, lField, stof( lToken ), lOperator );
222                                 }
223                         }
224                 } else { // lets have a try it with or and string contain
225                         sethostcachemaskstring( lOrPos, SLIST_FIELD_MAP, lToken, SLIST_TEST_CONTAINS );
226                         lOrPos = lOrPos + 1;
227                         sethostcachemaskstring( lOrPos, SLIST_FIELD_NAME, lToken, SLIST_TEST_CONTAINS );
228                         lOrPos = lOrPos + 1;
229                         //sethostcachemasknumber( lOrPos, SLIST_FIELD_MOD, lToken, SLIST_TEST_CONTAINS );
230                         //lOrPos = lOrPos + 1;
231                 }
232         }
233 :finish
234         HostCache_ResortViewSet();
235 #undef GetNextToken()
236 };