Browse Source

engine: client: touch security, add unprivileged for buttons added from server, force it and client flags

pull/2/head
Alibek Omarov 3 years ago committed by a1batross
parent
commit
664506f79e
  1. 15
      engine/client/cl_mobile.c
  2. 202
      engine/client/in_touch.c
  3. 9
      engine/client/input.h

15
engine/client/cl_mobile.c

@ -93,6 +93,15 @@ static void *pfnGetNativeObject( const char *obj )
return Platform_GetNativeObject( obj ); return Platform_GetNativeObject( obj );
} }
static void pfnTouch_HideButtons( const char *name, byte state )
{
Touch_HideButtons( name, state, true );
}
static void pfnTouch_RemoveButton( const char *name )
{
Touch_RemoveButton( name, true );
}
static mobile_engfuncs_t gpMobileEngfuncs = static mobile_engfuncs_t gpMobileEngfuncs =
{ {
@ -101,9 +110,9 @@ static mobile_engfuncs_t gpMobileEngfuncs =
pfnEnableTextInput, pfnEnableTextInput,
Touch_AddClientButton, Touch_AddClientButton,
Touch_AddDefaultButton, Touch_AddDefaultButton,
Touch_HideButtons, pfnTouch_HideButtons,
Touch_RemoveButton, pfnTouch_RemoveButton,
(void*)Touch_SetClientOnly, Touch_SetClientOnly,
Touch_ResetDefaultButtons, Touch_ResetDefaultButtons,
pfnDrawScaledCharacter, pfnDrawScaledCharacter,
Sys_Warn, Sys_Warn,

202
engine/client/in_touch.c

@ -134,6 +134,9 @@ struct touch_s
qboolean configchanged; qboolean configchanged;
} touch; } touch;
// private to the engine flags
#define TOUCH_FL_UNPRIVILEGED BIT( 10 )
touchdefaultbutton_t g_DefaultButtons[256]; touchdefaultbutton_t g_DefaultButtons[256];
int g_LastDefaultButton; int g_LastDefaultButton;
@ -455,28 +458,42 @@ static void Touch_Stroke_f( void )
MakeRGBA( touch.scolor, Q_atoi( Cmd_Argv( 2 ) ), Q_atoi( Cmd_Argv( 3 ) ), Q_atoi( Cmd_Argv( 4 ) ), Q_atoi( Cmd_Argv( 5 ) ) ); MakeRGBA( touch.scolor, Q_atoi( Cmd_Argv( 2 ) ), Q_atoi( Cmd_Argv( 3 ) ), Q_atoi( Cmd_Argv( 4 ) ), Q_atoi( Cmd_Argv( 5 ) ) );
} }
static touch_button_t *Touch_FindButton( touchbuttonlist_t *list, const char *name ) static touch_button_t *Touch_FindButton( touchbuttonlist_t *list, const char *name, qboolean privileged )
{ {
touch_button_t *button; touch_button_t *button;
for( button = list->first; button; button = button->next ) for( button = list->first; button; button = button->next )
if( !Q_strncmp( button->name, name, sizeof( button->name ))) {
if( !privileged && !FBitSet( button->flags, TOUCH_FL_UNPRIVILEGED ))
continue;
if( Q_strncmp( button->name, name, sizeof( button->name )))
continue;
return button; return button;
}
return NULL; return NULL;
} }
static touch_button_t *Touch_FindFirst( touchbuttonlist_t *list, const char *name ) static touch_button_t *Touch_FindFirst( touchbuttonlist_t *list, const char *name, qboolean privileged )
{ {
touch_button_t *button; touch_button_t *button;
for( button = list->first; button; button = button->next ) for( button = list->first; button; button = button->next )
{
if( !privileged && !FBitSet( button->flags, TOUCH_FL_UNPRIVILEGED ))
continue;
if(( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name )) || !Q_strncmp( name, button->name, sizeof( button->name ))) if(( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name )) || !Q_strncmp( name, button->name, sizeof( button->name )))
{
return button; return button;
}
}
return NULL; return NULL;
} }
void Touch_SetClientOnly( qboolean state ) void Touch_SetClientOnly( byte state )
{ {
touch.clientonly = state; touch.clientonly = state;
host.mouse_visible = state; host.mouse_visible = state;
@ -511,13 +528,13 @@ static void Touch_SetClientOnly_f( void )
Touch_SetClientOnly( Q_atoi( Cmd_Argv( 1 ))); Touch_SetClientOnly( Q_atoi( Cmd_Argv( 1 )));
} }
static void Touch_RemoveButtonFromList( touchbuttonlist_t *list, const char *name ) static void Touch_RemoveButtonFromList( touchbuttonlist_t *list, const char *name, qboolean privileged )
{ {
touch_button_t *button; touch_button_t *button;
IN_TouchEditClear(); IN_TouchEditClear();
while(( button = Touch_FindFirst( &touch.list_user, name ))) while(( button = Touch_FindFirst( &touch.list_user, name, !privileged )))
{ {
if( button->prev ) if( button->prev )
button->prev->next = button->next; button->prev->next = button->next;
@ -534,9 +551,9 @@ static void Touch_RemoveButtonFromList( touchbuttonlist_t *list, const char *nam
} }
void Touch_RemoveButton( const char *name ) void Touch_RemoveButton( const char *name, qboolean privileged )
{ {
Touch_RemoveButtonFromList( &touch.list_user, name ); Touch_RemoveButtonFromList( &touch.list_user, name, privileged );
} }
static void IN_TouchRemoveButton_f( void ) static void IN_TouchRemoveButton_f( void )
@ -547,7 +564,7 @@ static void IN_TouchRemoveButton_f( void )
return; return;
} }
Touch_RemoveButton( Cmd_Argv( 1 )); Touch_RemoveButton( Cmd_Argv( 1 ), Cmd_CurrentCommandIsPrivileged());
} }
static void Touch_ClearList( touchbuttonlist_t *list ) static void Touch_ClearList( touchbuttonlist_t *list )
@ -578,9 +595,9 @@ static void Touch_SetColor( touchbuttonlist_t *list, const char *name, byte *col
} }
} }
static void Touch_SetTexture( touchbuttonlist_t *list, const char *name, const char *texture ) static void Touch_SetTexture( touchbuttonlist_t *list, const char *name, const char *texture, qboolean privileged )
{ {
touch_button_t *button = Touch_FindButton( list, name ); touch_button_t *button = Touch_FindButton( list, name, privileged );
if( !button ) if( !button )
return; return;
@ -605,12 +622,15 @@ static void Touch_SetCommand( touch_button_t *button, const char *command )
button->type = touch_wheel; button->type = touch_wheel;
} }
void Touch_HideButtons( const char *name, byte hide ) void Touch_HideButtons( const char *name, byte hide, qboolean privileged )
{ {
touch_button_t *button; touch_button_t *button;
for( button = touch.list_user.first; button; button = button->next) for( button = touch.list_user.first; button; button = button->next)
{ {
if( !privileged && !FBitSet( button->flags, TOUCH_FL_UNPRIVILEGED ))
continue;
if(( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name )) || !Q_strncmp( name, button->name, sizeof( button->name ))) if(( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name )) || !Q_strncmp( name, button->name, sizeof( button->name )))
{ {
if( hide ) if( hide )
@ -635,7 +655,7 @@ static void Touch_Hide_f( void )
return; return;
} }
Touch_HideButtons( Cmd_Argv( 1 ), true ); Touch_HideButtons( Cmd_Argv( 1 ), true, Cmd_CurrentCommandIsPrivileged() );
} }
static void Touch_Show_f( void ) static void Touch_Show_f( void )
@ -646,14 +666,17 @@ static void Touch_Show_f( void )
return; return;
} }
Touch_HideButtons( Cmd_Argv( 1 ), false ); Touch_HideButtons( Cmd_Argv( 1 ), false, Cmd_CurrentCommandIsPrivileged() );
} }
static void Touch_FadeButtons( touchbuttonlist_t *list, const char *name, float speed, float end, float start ) static void Touch_FadeButtons( touchbuttonlist_t *list, const char *name, float speed, float end, float start, qboolean privileged )
{ {
touch_button_t *button; touch_button_t *button;
for( button = list->first; button; button = button->next) for( button = list->first; button; button = button->next)
{ {
if( !privileged && !FBitSet( button->flags, TOUCH_FL_UNPRIVILEGED ))
continue;
if(( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name )) || !Q_strncmp( name, button->name, sizeof( button->name ))) if(( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name )) || !Q_strncmp( name, button->name, sizeof( button->name )))
{ {
if( start >= 0 ) if( start >= 0 )
@ -678,7 +701,8 @@ static void Touch_Fade_f( void )
return; return;
} }
Touch_FadeButtons( &touch.list_user, Cmd_Argv( 1 ), Q_atof( Cmd_Argv( 2 )), Q_atof( Cmd_Argv( 3 )), start ); Touch_FadeButtons( &touch.list_user,Cmd_Argv( 1 ), Q_atof( Cmd_Argv( 2 )), Q_atof( Cmd_Argv( 3 )),
start, Cmd_CurrentCommandIsPrivileged() );
} }
static void Touch_SetColor_f( void ) static void Touch_SetColor_f( void )
@ -697,7 +721,7 @@ static void Touch_SetTexture_f( void )
{ {
if( Cmd_Argc() == 3 ) if( Cmd_Argc() == 3 )
{ {
Touch_SetTexture( &touch.list_user, Cmd_Argv( 1 ), Cmd_Argv( 2 ) ); Touch_SetTexture( &touch.list_user, Cmd_Argv( 1 ), Cmd_Argv( 2 ), Cmd_CurrentCommandIsPrivileged() );
return; return;
} }
Con_Printf( S_USAGE "touch_settexture <name> <file>\n" ); Con_Printf( S_USAGE "touch_settexture <name> <file>\n" );
@ -707,9 +731,13 @@ static void Touch_SetFlags_f( void )
{ {
if( Cmd_Argc() == 3 ) if( Cmd_Argc() == 3 )
{ {
touch_button_t *button = Touch_FindButton( &touch.list_user, Cmd_Argv( 1 ) ); qboolean privileged = Cmd_CurrentCommandIsPrivileged();
touch_button_t *button = Touch_FindButton( &touch.list_user, Cmd_Argv( 1 ), privileged );
if( button ) if( button )
button->flags = Q_atoi( Cmd_Argv( 2 ) ); {
button->flags = ( privileged ? 0 : TOUCH_FL_UNPRIVILEGED | TOUCH_FL_CLIENT ) | Q_atoi( Cmd_Argv( 2 ));
}
return; return;
} }
Con_Printf( S_USAGE "touch_setflags <name> <file>\n" ); Con_Printf( S_USAGE "touch_setflags <name> <file>\n" );
@ -719,7 +747,7 @@ static void Touch_SetCommand_f( void )
{ {
if( Cmd_Argc() == 3 ) if( Cmd_Argc() == 3 )
{ {
touch_button_t *button = Touch_FindButton( &touch.list_user, Cmd_Argv(1) ); touch_button_t *button = Touch_FindButton( &touch.list_user, Cmd_Argv(1), Cmd_CurrentCommandIsPrivileged() );
if( !button ) if( !button )
Con_Printf( S_ERROR "no such button" ); Con_Printf( S_ERROR "no such button" );
@ -744,18 +772,22 @@ static void Touch_ReloadConfig_f( void )
Cbuf_AddText( va("exec %s\n", touch_config_file->string ) ); Cbuf_AddText( va("exec %s\n", touch_config_file->string ) );
} }
static touch_button_t *Touch_AddButton( touchbuttonlist_t *list, const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color ) static touch_button_t *Touch_AddButton( touchbuttonlist_t *list,
const char *name, const char *texture, const char *command,
float x1, float y1, float x2, float y2, byte *color,
qboolean privileged )
{ {
touch_button_t *button = Mem_Calloc( touch.mempool, sizeof( touch_button_t ) ); touch_button_t *button = Mem_Calloc( touch.mempool, sizeof( touch_button_t ) );
button->texture = -1; button->texture = -1;
Q_strncpy( button->texturefile, texture, sizeof( B( texturefile ))); Q_strncpy( button->texturefile, texture, sizeof( B( texturefile )));
Q_strncpy( button->name, name, sizeof( B( name ))); Q_strncpy( button->name, name, sizeof( B( name )));
Touch_RemoveButtonFromList( list, name ); //replace if exist Touch_RemoveButtonFromList( list, name, privileged ); //replace if exist
button->x1 = x1; button->x1 = x1;
button->y1 = y1; button->y1 = y1;
button->x2 = x2; button->x2 = x2;
button->y2 = y2; button->y2 = y2;
button->flags = privileged ? 0 : TOUCH_FL_UNPRIVILEGED | TOUCH_FL_CLIENT;
MakeRGBA( button->color, color[0], color[1], color[2], color[3] ); MakeRGBA( button->color, color[0], color[1], color[2], color[3] );
button->command[0] = 0; button->command[0] = 0;
button->flags = 0; button->flags = 0;
@ -788,7 +820,7 @@ void Touch_AddClientButton( const char *name, const char *texture, const char *c
{ {
y2 = y1 + ( x2 - x1 ) * (SCR_W/SCR_H) * aspect; y2 = y1 + ( x2 - x1 ) * (SCR_W/SCR_H) * aspect;
} }
button = Touch_AddButton( &touch.list_user, name, texture, command, x1, y1, x2, y2, color ); button = Touch_AddButton( &touch.list_user, name, texture, command, x1, y1, x2, y2, color, true );
button->flags |= flags | TOUCH_FL_CLIENT | TOUCH_FL_NOEDIT; button->flags |= flags | TOUCH_FL_CLIENT | TOUCH_FL_NOEDIT;
button->aspect = aspect; button->aspect = aspect;
} }
@ -815,7 +847,7 @@ static void Touch_LoadDefaults_f( void )
} }
IN_TouchCheckCoords( &x1, &y1, &x2, &y2 ); IN_TouchCheckCoords( &x1, &y1, &x2, &y2 );
button = Touch_AddButton( &touch.list_user, g_DefaultButtons[i].name, g_DefaultButtons[i].texturefile, g_DefaultButtons[i].command, x1, y1, x2, y2, g_DefaultButtons[i].color ); button = Touch_AddButton( &touch.list_user, g_DefaultButtons[i].name, g_DefaultButtons[i].texturefile, g_DefaultButtons[i].command, x1, y1, x2, y2, g_DefaultButtons[i].color, true );
button->flags |= g_DefaultButtons[i].flags; button->flags |= g_DefaultButtons[i].flags;
button->aspect = g_DefaultButtons[i].aspect; button->aspect = g_DefaultButtons[i].aspect;
} }
@ -855,51 +887,66 @@ static void Touch_AddButton_f( void )
{ {
rgba_t color; rgba_t color;
int argc = Cmd_Argc( ); int argc = Cmd_Argc( );
touch_button_t *button = NULL;
const char *name, *texture, *command;
float x1, y1, x2, y2;
qboolean privileged = Cmd_CurrentCommandIsPrivileged();
if( argc >= 12 ) if( argc < 4 )
{ {
touch_button_t *button; Con_Printf( S_USAGE "touch_addbutton <name> <texture> <command> [<x1> <y1> <x2> <y2> [ r g b a ] ]\n" );
MakeRGBA( color, Q_atoi( Cmd_Argv(8) ), Q_atoi( Cmd_Argv(9) ), return;
Q_atoi( Cmd_Argv(10) ), Q_atoi( Cmd_Argv(11) ) ); }
button = Touch_AddButton( &touch.list_user, Cmd_Argv(1), Cmd_Argv(2), Cmd_Argv(3),
Q_atof( Cmd_Argv(4) ), Q_atof( Cmd_Argv(5) ), name = Cmd_Argv( 1 );
Q_atof( Cmd_Argv(6) ), Q_atof( Cmd_Argv(7) ) , texture = Cmd_Argv( 2 );
color ); command = Cmd_Argv( 3 );
if( argc >= 13 )
if( argc < 8 )
{ {
button->flags = Q_atoi( Cmd_Argv(12) ); x1 = y1 = 0.4f;
x2 = y2 = 0.6f;
} }
if( argc >= 14 ) else
{ {
// Recalculate button coordinates aspect ratio x1 = Q_atof( Cmd_Argv( 4 ));
// This is feature for distributed configs y1 = Q_atof( Cmd_Argv( 5 ));
float aspect = Q_atof( Cmd_Argv(13) ); x2 = Q_atof( Cmd_Argv( 6 ));
if( aspect ) y2 = Q_atof( Cmd_Argv( 7 ));
}
if( argc < 12 )
{ {
if( B(texturefile)[0] != '#' ) MakeRGBA( color, 255, 255, 255, 255 );
B(y2) = B(y1) + ( B(x2) - B(x1) ) * (SCR_W/SCR_H) * aspect;
B(aspect) = aspect;
} }
else
{
MakeRGBA( color,
Q_atoi( Cmd_Argv( 8 )),
Q_atoi( Cmd_Argv( 9 )),
Q_atoi( Cmd_Argv( 10 )),
Q_atoi( Cmd_Argv( 11 )));
} }
return; button = Touch_AddButton( &touch.list_user, name, texture, command, x1, y1, x2, y2, color, privileged );
}
if( argc == 8 ) if( argc >= 13 )
{ {
MakeRGBA( color, 255, 255, 255, 255 ); SetBits( button->flags, Q_atoi( Cmd_Argv( 12 )));
Touch_AddButton( &touch.list_user, Cmd_Argv(1), Cmd_Argv(2), Cmd_Argv(3),
Q_atof( Cmd_Argv(4) ), Q_atof( Cmd_Argv(5) ),
Q_atof( Cmd_Argv(6) ), Q_atof( Cmd_Argv(7) ),
color );
return;
} }
if( argc == 4 )
if( argc >= 14 )
{ {
MakeRGBA( color, 255, 255, 255, 255 ); // Recalculate button coordinates aspect ratio
Touch_AddButton( &touch.list_user, Cmd_Argv(1), Cmd_Argv(2), Cmd_Argv(3), 0.4, 0.4, 0.6, 0.6, color ); // This is feature for distributed configs
return; float aspect = Q_atof( Cmd_Argv( 13 ));
if( aspect )
{
if( B( texturefile )[0] != '#' )
B( y2 ) = B( y1 ) + ( B( x2 ) - B( x1 )) * ( SCR_W / SCR_H ) * aspect;
B( aspect ) = aspect;
}
} }
Con_Printf( S_USAGE "touch_addbutton <name> <texture> <command> [<x1> <y1> <x2> <y2> [ r g b a ] ]\n" );
} }
static void Touch_EnableEdit_f( void ) static void Touch_EnableEdit_f( void )
@ -946,26 +993,29 @@ static void Touch_InitEditor( void )
float x = 0.1f * (SCR_H/SCR_W); float x = 0.1f * (SCR_H/SCR_W);
float y = 0.05f; float y = 0.05f;
touch_button_t *temp; touch_button_t *temp;
rgba_t color;
MakeRGBA( color, 255, 255, 255, 255 );
Touch_ClearList( &touch.list_edit ); Touch_ClearList( &touch.list_edit );
temp = Touch_AddButton( &touch.list_edit, "close", "touch_default/edit_close.tga", "touch_disableedit", 0, y, x, y + 0.1f, (byte*)"\xff\xff\xff\xff" ); temp = Touch_AddButton( &touch.list_edit, "close", "touch_default/edit_close.tga", "touch_disableedit", 0, y, x, y + 0.1f, color, true );
SetBits( temp->flags, TOUCH_FL_NOEDIT ); SetBits( temp->flags, TOUCH_FL_NOEDIT );
temp = Touch_AddButton( &touch.list_edit, "close", "#Close and save", "", x, y, x + 0.2f, y + 0.1f, (byte*)"\xff\xff\xff\xff" ); temp = Touch_AddButton( &touch.list_edit, "close", "#Close and save", "", x, y, x + 0.2f, y + 0.1f, color, true );
SetBits( temp->flags, TOUCH_FL_NOEDIT ); SetBits( temp->flags, TOUCH_FL_NOEDIT );
y += 0.2f; y += 0.2f;
temp = Touch_AddButton( &touch.list_edit, "cancel", "touch_default/edit_reset.tga", "touch_reloadconfig", 0, y, x, y + 0.1f, (byte*)"\xff\xff\xff\xff" ); temp = Touch_AddButton( &touch.list_edit, "cancel", "touch_default/edit_reset.tga", "touch_reloadconfig", 0, y, x, y + 0.1f, color, true );
SetBits( temp->flags, TOUCH_FL_NOEDIT ); SetBits( temp->flags, TOUCH_FL_NOEDIT );
temp = Touch_AddButton( &touch.list_edit, "close", "#Cancel and reset", "", x, y, x + 0.2f, y + 0.1f, (byte*)"\xff\xff\xff\xff" ); temp = Touch_AddButton( &touch.list_edit, "close", "#Cancel and reset", "", x, y, x + 0.2f, y + 0.1f, color, true );
SetBits( temp->flags, TOUCH_FL_NOEDIT ); SetBits( temp->flags, TOUCH_FL_NOEDIT );
y += 0.2f; y += 0.2f;
touch.hidebutton = Touch_AddButton( &touch.list_edit, "showhide", "touch_default/edit_hide.tga", "touch_toggleselection", 0, y, x, y + 0.1f, (byte*)"\xff\xff\xff\xff" ); touch.hidebutton = Touch_AddButton( &touch.list_edit, "showhide", "touch_default/edit_hide.tga", "touch_toggleselection", 0, y, x, y + 0.1f, color, true );
SetBits( touch.hidebutton->flags, TOUCH_FL_HIDE | TOUCH_FL_NOEDIT ); SetBits( touch.hidebutton->flags, TOUCH_FL_HIDE | TOUCH_FL_NOEDIT );
} }
@ -1014,25 +1064,25 @@ void Touch_Init( void )
Cmd_AddCommand( "touch_addbutton", Touch_AddButton_f, "add native touch button" ); Cmd_AddCommand( "touch_addbutton", Touch_AddButton_f, "add native touch button" );
Cmd_AddCommand( "touch_removebutton", IN_TouchRemoveButton_f, "remove native touch button" ); Cmd_AddCommand( "touch_removebutton", IN_TouchRemoveButton_f, "remove native touch button" );
Cmd_AddCommand( "touch_enableedit", Touch_EnableEdit_f, "enable button editing mode" ); Cmd_AddRestrictedCommand( "touch_enableedit", Touch_EnableEdit_f, "enable button editing mode" );
Cmd_AddCommand( "touch_disableedit", Touch_DisableEdit_f, "disable button editing mode" ); Cmd_AddRestrictedCommand( "touch_disableedit", Touch_DisableEdit_f, "disable button editing mode" );
Cmd_AddCommand( "touch_settexture", Touch_SetTexture_f, "change button texture" ); Cmd_AddCommand( "touch_settexture", Touch_SetTexture_f, "change button texture" );
Cmd_AddCommand( "touch_setcolor", Touch_SetColor_f, "change button color" ); Cmd_AddCommand( "touch_setcolor", Touch_SetColor_f, "change button color" );
Cmd_AddCommand( "touch_setcommand", Touch_SetCommand_f, "change button command" ); Cmd_AddCommand( "touch_setcommand", Touch_SetCommand_f, "change button command" );
Cmd_AddCommand( "touch_setflags", Touch_SetFlags_f, "change button flags (be careful)" ); Cmd_AddCommand( "touch_setflags", Touch_SetFlags_f, "change button flags (be careful)" );
Cmd_AddCommand( "touch_show", Touch_Show_f, "show button" ); Cmd_AddCommand( "touch_show", Touch_Show_f, "show button" );
Cmd_AddCommand( "touch_hide", Touch_Hide_f, "hide button" ); Cmd_AddCommand( "touch_hide", Touch_Hide_f, "hide button" );
Cmd_AddCommand( "touch_list", Touch_ListButtons_f, "list buttons" ); Cmd_AddRestrictedCommand( "touch_list", Touch_ListButtons_f, "list buttons" );
Cmd_AddRestrictedCommand( "touch_removeall", Touch_RemoveAll_f, "remove all buttons" ); Cmd_AddRestrictedCommand( "touch_removeall", Touch_RemoveAll_f, "remove all buttons" );
Cmd_AddRestrictedCommand( "touch_loaddefaults", Touch_LoadDefaults_f, "generate config from defaults" ); Cmd_AddRestrictedCommand( "touch_loaddefaults", Touch_LoadDefaults_f, "generate config from defaults" );
Cmd_AddCommand( "touch_roundall", Touch_RoundAll_f, "round all buttons coordinates to grid" ); Cmd_AddRestrictedCommand( "touch_roundall", Touch_RoundAll_f, "round all buttons coordinates to grid" );
Cmd_AddRestrictedCommand( "touch_exportconfig", Touch_ExportConfig_f, "export config keeping aspect ratio" ); Cmd_AddRestrictedCommand( "touch_exportconfig", Touch_ExportConfig_f, "export config keeping aspect ratio" );
Cmd_AddCommand( "touch_set_stroke", Touch_Stroke_f, "set global stroke width and color" ); Cmd_AddCommand( "touch_set_stroke", Touch_Stroke_f, "set global stroke width and color" );
Cmd_AddCommand( "touch_setclientonly", Touch_SetClientOnly_f, "when 1, only client buttons are shown" ); Cmd_AddCommand( "touch_setclientonly", Touch_SetClientOnly_f, "when 1, only client buttons are shown" );
Cmd_AddRestrictedCommand( "touch_reloadconfig", Touch_ReloadConfig_f, "load config, not saving changes" ); Cmd_AddRestrictedCommand( "touch_reloadconfig", Touch_ReloadConfig_f, "load config, not saving changes" );
Cmd_AddRestrictedCommand( "touch_writeconfig", Touch_WriteConfig, "save current config" ); Cmd_AddRestrictedCommand( "touch_writeconfig", Touch_WriteConfig, "save current config" );
Cmd_AddRestrictedCommand( "touch_deleteprofile", Touch_DeleteProfile_f, "delete profile by name" ); Cmd_AddRestrictedCommand( "touch_deleteprofile", Touch_DeleteProfile_f, "delete profile by name" );
Cmd_AddCommand( "touch_generate_code", Touch_GenerateCode_f, "create code sample for mobility API" ); Cmd_AddRestrictedCommand( "touch_generate_code", Touch_GenerateCode_f, "create code sample for mobility API" );
Cmd_AddCommand( "touch_fade", Touch_Fade_f, "start fade animation for selected buttons" ); Cmd_AddCommand( "touch_fade", Touch_Fade_f, "start fade animation for selected buttons" );
Cmd_AddRestrictedCommand( "touch_toggleselection", Touch_ToggleSelection_f, "toggle vidibility on selected button in editor" ); Cmd_AddRestrictedCommand( "touch_toggleselection", Touch_ToggleSelection_f, "toggle vidibility on selected button in editor" );
@ -1630,7 +1680,9 @@ static qboolean Touch_ButtonPress( touchbuttonlist_t *list, touchEventType type,
// command down: just execute command // command down: just execute command
Q_snprintf( command, sizeof( command ), "%s\n", button->command ); Q_snprintf( command, sizeof( command ), "%s\n", button->command );
Cbuf_AddText( command ); if( FBitSet( B( flags ), TOUCH_FL_UNPRIVILEGED ))
Cbuf_AddFilteredText( command );
else Cbuf_AddText( command );
// increase precision // increase precision
if( FBitSet( B(flags), TOUCH_FL_PRECISION )) if( FBitSet( B(flags), TOUCH_FL_PRECISION ))
@ -1654,7 +1706,9 @@ static qboolean Touch_ButtonPress( touchbuttonlist_t *list, touchEventType type,
Q_snprintf( touch.wheel_end, sizeof( touch.wheel_end ), "%s\n", Cmd_Argv( 3 ) ); Q_snprintf( touch.wheel_end, sizeof( touch.wheel_end ), "%s\n", Cmd_Argv( 3 ) );
if( Q_snprintf( command, sizeof( command ), "%s\n", Cmd_Argv( 4 ) ) > 1) if( Q_snprintf( command, sizeof( command ), "%s\n", Cmd_Argv( 4 ) ) > 1)
{ {
Cbuf_AddText( command ); if( FBitSet( B( flags ), TOUCH_FL_UNPRIVILEGED ))
Cbuf_AddFilteredText( command );
else Cbuf_AddText( command );
touch.wheel_count++; touch.wheel_count++;
} }
@ -1776,8 +1830,12 @@ static qboolean Touch_ButtonPress( touchbuttonlist_t *list, touchEventType type,
char command[256]; char command[256];
Q_snprintf( command, sizeof( command ), "%s\n", button->command ); Q_snprintf( command, sizeof( command ), "%s\n", button->command );
command[0] = '-'; command[0] = '-';
Cbuf_AddText( command );
if( FBitSet( B( flags ), TOUCH_FL_UNPRIVILEGED ))
Cbuf_AddFilteredText( command );
else Cbuf_AddText( command );
} }
// disable precision mode // disable precision mode
@ -1791,7 +1849,11 @@ static qboolean Touch_ButtonPress( touchbuttonlist_t *list, touchEventType type,
if( button->type == touch_wheel ) if( button->type == touch_wheel )
{ {
if( touch.wheel_count ) if( touch.wheel_count )
Cbuf_AddText( touch.wheel_end ); {
if( FBitSet( B( flags ), TOUCH_FL_UNPRIVILEGED ))
Cbuf_AddFilteredText( touch.wheel_end );
else Cbuf_AddText( touch.wheel_end );
}
// disable precision mode // disable precision mode
if( B(flags) & TOUCH_FL_PRECISION ) if( B(flags) & TOUCH_FL_PRECISION )

9
engine/client/input.h

@ -61,12 +61,9 @@ extern convar_t *touch_enable;
extern convar_t *touch_emulate; extern convar_t *touch_emulate;
void Touch_Draw( void ); void Touch_Draw( void );
void Touch_SetClientOnly( qboolean state ); void Touch_SetClientOnly( byte state );
void Touch_RemoveButton( const char *name ); void Touch_RemoveButton( const char *name, qboolean privileged );
void Touch_HideButtons( const char *name, unsigned char hide ); void Touch_HideButtons( const char *name, unsigned char hide, qboolean privileged );
//void IN_TouchSetCommand( const char *name, const char *command );
//void IN_TouchSetTexture( const char *name, const char *texture );
//void IN_TouchSetColor( const char *name, byte *color );
void Touch_AddClientButton( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags ); void Touch_AddClientButton( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags );
void Touch_AddDefaultButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags ); void Touch_AddDefaultButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags );
void Touch_WriteConfig( void ); void Touch_WriteConfig( void );

Loading…
Cancel
Save