DEADSOFTWARE

System username used as player's nickname by default
[d2df-sdl.git] / src / shared / envvars.pas
index 6f92b40786a857eea425680bfbc4068ffa4e145b..3774eab2fe277edbd168c160de436c954d3c5007 100644 (file)
@@ -1,4 +1,4 @@
-(* Copyright (C)  DooM 2D:Forever Developers
+(* Copyright (C)  Doom 2D: Forever Developers
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *)
-{$MODE OBJFPC}
+{$INCLUDE a_modes.inc}
+{.$MODE OBJFPC}
 unit envvars;
 
 interface
 
-uses SysUtils, CTypes;
+  uses SysUtils, CTypes;
 
-function SetEnvVar(const VarName: AnsiString; const VarVal: AnsiString): Boolean;
+  function SetEnvVar(const VarName: AnsiString; const VarVal: AnsiString): Boolean;
+  function GetUserName: String;
 
 implementation
 
@@ -45,4 +47,15 @@ begin
   Result := (setenv(PChar(VarName), PChar(VarVal), 1) = 0);
 end;
 
+  function GetUserName: String;
+  begin
+    {$IF DEFINED(WINDOWS)}
+      Result := SysUtils.GetEnvironmentVariable('USERNAME')
+    {$ELSEIF DEFINED(UNIX)}
+      Result := SysUtils.GetEnvironmentVariable('USER')
+    {$ELSE}
+      Result := ''
+    {$ENDIF}
+  end;
+
 end.