@@ -3563,7 +3563,7 @@ static int lan_config_cursor = -1;
35633563
35643564static int lan_config_port ;
35653565static char lan_config_portname [6 ];
3566- static char lan_config_joinname [22 ];
3566+ static char lan_config_joinname [33 ];
35673567
35683568static void M_Menu_LanConfig_f (void )
35693569{
@@ -3632,7 +3632,7 @@ static void M_LanConfig_Draw (cb_context_t *cbx)
36323632
36333633 y += 8 ; // for the port's box
36343634 M_Print (cbx , basex , y , "Port" );
3635- M_DrawTextBox (cbx , basex + 8 * 8 , y - 8 , 6 , 1 );
3635+ M_DrawTextBox (cbx , basex + 8 * 8 , y - 8 , countof ( lan_config_portname ) , 1 );
36363636 M_Print (cbx , basex + 9 * 8 , y , lan_config_portname );
36373637 M_Mouse_UpdateCursor (& lan_config_cursor , basex , 320 , y , 8 , 0 );
36383638 if (lan_config_cursor == 0 )
@@ -3654,11 +3654,11 @@ static void M_LanConfig_Draw (cb_context_t *cbx)
36543654 M_Mouse_UpdateCursor (& lan_config_cursor , basex , 320 , y , 8 , 2 );
36553655 if (lan_config_cursor == 2 )
36563656 Draw_Character (cbx , basex - 8 , y , 12 + ((int )(realtime * 4 ) & 1 ));
3657- y += 8 ;
3657+ y += 24 ;
36583658
36593659 M_Print (cbx , basex , y , "Join game at:" );
3660- y += 24 ;
3661- M_DrawTextBox (cbx , basex + 8 , y - 8 , 22 , 1 );
3660+ y += 12 ;
3661+ M_DrawTextBox (cbx , basex + 8 , y - 8 , countof ( lan_config_joinname ) , 1 );
36623662 M_Print (cbx , basex + 16 , y , lan_config_joinname );
36633663 M_Mouse_UpdateCursor (& lan_config_cursor , basex , 320 , y , 8 , 3 );
36643664 if (lan_config_cursor == 3 )
@@ -3756,6 +3756,56 @@ static void M_LanConfig_Key (int key)
37563756 lan_config_joinname [strlen (lan_config_joinname ) - 1 ] = 0 ;
37573757 }
37583758 break ;
3759+
3760+ case 'v' :
3761+ case 'V' :
3762+ // Ctrl + v : paste a hostname
3763+ if (lan_config_cursor == 3 &&
3764+ #if defined(PLATFORM_OSX ) || defined(PLATFORM_MAC )
3765+ (keydown [K_COMMAND ])
3766+ #else
3767+ (keydown [K_CTRL ])
3768+ #endif
3769+ )
3770+ {
3771+ const int current_joinname_size = strlen (lan_config_joinname );
3772+
3773+ const int joinname_remaining_room_size = countof (lan_config_joinname ) - 1 - current_joinname_size ;
3774+
3775+ if (joinname_remaining_room_size > 0 )
3776+ {
3777+ char raw_join_address [countof (lan_config_joinname )];
3778+
3779+ q_strlcpy (raw_join_address , lan_config_joinname , sizeof (lan_config_joinname ));
3780+
3781+ char * clipboard_text = PL_GetClipboardData ();
3782+
3783+ // append the existing clipboard text
3784+ if (clipboard_text )
3785+ q_strlcpy (raw_join_address + current_joinname_size , clipboard_text , joinname_remaining_room_size );
3786+
3787+ // Check if the resulting raw_join_address is of form 'address:port', in this case overwrite lan_config_portname with it
3788+ size_t nb_parts = 0 ;
3789+
3790+ char * * split_adress = q_strsplit (raw_join_address , ":" , & nb_parts );
3791+
3792+ if (nb_parts == 2 && atoi (split_adress [1 ]) > 0 && atoi (split_adress [1 ]) <= 65535 )
3793+ {
3794+ // overwrite existing port
3795+ q_strlcpy (lan_config_portname , split_adress [1 ], sizeof (lan_config_portname ));
3796+
3797+ // set join name from the first part:
3798+ q_strlcpy (lan_config_joinname , q_strtrim (split_adress [0 ]), sizeof (lan_config_joinname ));
3799+ }
3800+ else
3801+ {
3802+ q_strlcpy (lan_config_joinname , raw_join_address , sizeof (lan_config_joinname ));
3803+ }
3804+ Mem_Free (split_adress );
3805+ Mem_Free (clipboard_text );
3806+ } // end if enough room to Ctrl+v
3807+ }
3808+ break ;
37593809 }
37603810
37613811 if (StartingGame && lan_config_cursor >= 2 )
@@ -3784,15 +3834,16 @@ static void M_LanConfig_Char (int key)
37843834 if (key < '0' || key > '9' )
37853835 return ;
37863836 l = strlen (lan_config_portname );
3787- if (l < 5 )
3837+ // append one character, assure null-termination
3838+ if (l < countof (lan_config_portname ) - 1 )
37883839 {
37893840 lan_config_portname [l + 1 ] = 0 ;
37903841 lan_config_portname [l ] = key ;
37913842 }
37923843 break ;
37933844 case 3 :
37943845 l = strlen (lan_config_joinname );
3795- if (l < 21 )
3846+ if (l < countof ( lan_config_joinname ) - 1 )
37963847 {
37973848 lan_config_joinname [l + 1 ] = 0 ;
37983849 lan_config_joinname [l ] = key ;
0 commit comments