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