]> icculus.org git repositories - divverent/nexuiz.git/blob - data/menuqc/custom/joingame.qm
Fixed the crosshair selection.
[divverent/nexuiz.git] / data / menuqc / 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_JumpToJoinGame =
48 {
49         local entity lItem;
50
51         resethostcachemasks();
52         sethostcachesort( SLIST_FIELD_PING, false );
53         HostCache_RefreshHostCache();
54
55         lItem = Menu_GetItem( "Normal::Panel" );
56         String_EntitySet( lItem, link, "JoinGame" );
57
58         Raise_Update( lItem );
59         Menu_UpdateRunFlags();
60         Menu_JumpToWindow( lItem._link, false, false );
61 };
62
63 // mask parser
64 /* query string format:
65    two types:
66 1) Prefix "mask" Advanced query
67         Format: ( and|or TYPE OP MASK [...] )*
68         TYPE :  one of the slist fields
69         OP:
70                 <;<=;>=;==;!= normal arithmetic comparison operators (default <=) (= instead of == also supported)
71                 $$ 'does contain' (default string op)
72                 !$ 'does not contain'
73                 : leads to default op
74
75         On every occurence of AND or OR a new mask of the spec type is created.
76         E.g. or name: "WWClan" ping: 200 and protocol == 3 maxplayers > 5
77         will create an or and an and mask
78 2) No prefix:
79         keyword *
80
81         notempty
82         compatible      (same net protocol version)
83         goodping        (ping <= 150)
84         mediumping      (ping <= 250)
85 */
86 #define GetNextToken    if( ++lTokenNum > lTokenCount ) goto finish; else lToken = argv( lTokenNum )
87 void() Nex_Action_ExecuteQuery =
88 {
89         local float lAndPos, lOrPos;
90         local float lTokenNum, lTokenCount;
91
92         resethostcachemasks();
93         lAndPos = SLIST_MASK_AND;
94         lOrPos = SLIST_MASK_OR;
95
96         lTokenCount = tokenize( self._target.value );
97
98         for( lTokenNum = 0 ; lTokenNum < lTokenCount ; ++lTokenNum ) {
99                 local string lToken;
100                 lToken = argv( lTokenNum );
101
102                 if( lToken == "notempty" ) {
103                         sethostcachemasknumber( lAndPos, SLIST_FIELD_NUMPLAYERS, 0, SLIST_TEST_NOTEQUAL );
104                         ++lAndPos;
105                 } else if( lToken == "compatible" ) {
106                         sethostcachemasknumber( lAndPos, SLIST_FIELD_PROTOCOL, NET_CURRENTPROTOCOL, SLIST_TEST_EQUAL );
107                         ++lAndPos;
108                 } else if( lToken == "goodping" ) {
109                         sethostcachemasknumber( lAndPos, SLIST_FIELD_PING, 150, SLIST_TEST_LESSEQUAL );
110                         ++lAndPos;
111                 } else if( lToken == "mediumping" ) {
112                         sethostcachemasknumber( lAndPos, SLIST_FIELD_PROTOCOL, 250, SLIST_TEST_LESSEQUAL );
113                         ++lAndPos;
114                 } else if( lToken == "mask" ) {
115                         // start the query loop
116                         GetNextToken;
117                         while( 1 ) {
118                                 local bool lAndMask;
119
120                                 if( lToken == "or" )
121                                         lAndMask = false;
122                                 else if( lToken == "and" )
123                                         lAndMask = true;
124                                 else
125                                         goto finish; // abort the parsing
126                                 // now parse all condition fields
127                                 while( 1 ) {
128                                         local float lField;
129                                         local float lOperator;
130                                         local bool  lIsStringArg;
131
132                                         GetNextToken;
133                                         // now get the field number
134                                         if( lToken == "cname" ) {
135                                                 lField = SLIST_FIELD_CNAME;
136                                                 lIsStringArg = true;
137                                         }
138                                         else if( lToken == "ping" ) {
139                                                 lField = SLIST_FIELD_PING;
140                                                 lIsStringArg = false;
141                                         }
142                                         else if( lToken == "game" ) {
143                                                 lField = SLIST_FIELD_GAME;
144                                                 lIsStringArg = true;
145                                         }
146                                         else if( lToken == "mod" ) {
147                                                 lField = SLIST_FIELD_MOD;
148                                                 lIsStringArg = true;
149                                         }
150                                         else if( lToken == "map" ) {
151                                                 lField = SLIST_FIELD_MAP;
152                                                 lIsStringArg = true;
153                                         }
154                                         else if( lToken == "name" ) {
155                                                 lField = SLIST_FIELD_NAME;
156                                                 lIsStringArg = true;
157                                         }
158                                         else if( lToken == "maxplayers" ) {
159                                                 lField = SLIST_FIELD_MAXPLAYERS;
160                                                 lIsStringArg = false;
161                                         }
162                                         else if( lToken == "numplayers" ) {
163                                                 lField = SLIST_FIELD_NUMPLAYERS;
164                                                 lIsStringArg = false;
165                                         }
166                                         else if( lToken == "protocol" ) {
167                                                 lField = SLIST_FIELD_PROTOCOL;
168                                                 lIsStringArg = false;
169                                         }
170                                         else
171                                         { // increment the mask pos and let upper check for or or and
172                                                 if( lAndMask )
173                                                         ++lAndPos;
174                                                 else
175                                                         ++lOrPos;
176                                                 break;
177                                         }
178                                         // now lets determine the comparison operator
179                                         GetNextToken;
180                                         if( lToken == "$$" )
181                                                 lOperator = SLIST_TEST_CONTAINS;
182                                         else if( lToken == "!$" )
183                                                 lOperator = SLIST_TEST_NOTCONTAIN;
184                                         else if( lToken == "<" )
185                                                 lOperator = SLIST_TEST_LESS;
186                                         else if( lToken == "<=" )
187                                                 lOperator = SLIST_TEST_LESSEQUAL;
188                                         else if( lToken == "==" || lToken == "=" )
189                                                 lOperator = SLIST_TEST_EQUAL;
190                                         else if( lToken == ">" )
191                                                 lOperator = SLIST_TEST_GREATER;
192                                         else if( lToken == ">=" )
193                                                 lOperator = SLIST_TEST_GREATEREQUAL;
194                                         else if( lToken == "!=" )
195                                                 lOperator = SLIST_TEST_NOTEQUAL;
196                                         else if( lToken == ":" )
197                                                 if( lIsStringArg )
198                                                         lOperator = SLIST_TEST_CONTAINS;
199                                                 else
200                                                         lOperator = SLIST_TEST_LESSEQUAL;
201                                         else
202                                                 goto finish; // abort the parsing
203
204                                         GetNextToken;
205                                         if( lIsStringArg )
206                                                 if( lAndMask )
207                                                         sethostcachemaskstring( lAndPos, lField, lToken, lOperator );
208                                                 else
209                                                         sethostcachemaskstring( lOrPos, lField, lToken, lOperator );
210                                         else
211                                                 if( lAndMask )
212                                                         sethostcachemasknumber( lAndPos, lField, stof( lToken ), lOperator );
213                                                 else
214                                                         sethostcachemasknumber( lOrPos, lField, stof( lToken ), lOperator );
215                                 }
216                         }
217                 } else { // lets have a try it with or and string contain
218                         sethostcachemaskstring( lOrPos, SLIST_FIELD_MAP, lToken, SLIST_TEST_CONTAINS );
219                         lOrPos = lOrPos + 1;
220                         sethostcachemaskstring( lOrPos, SLIST_FIELD_NAME, lToken, SLIST_TEST_CONTAINS );
221                         lOrPos = lOrPos + 1;
222                         //sethostcachemasknumber( lOrPos, SLIST_FIELD_MOD, lToken, SLIST_TEST_CONTAINS );
223                         //lOrPos = lOrPos + 1;
224                 }
225         }
226 :finish
227         HostCache_ResortViewSet();
228 #undef GetNextToken()
229 };