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