00001
00025 #include "menustate.h"
00026
00027 #include <string.h>
00028 #include <stdlib.h>
00029 #include <assert.h>
00030 #if defined(USE_GETTEXT) || defined(DOXYGEN)
00031 #include <wchar.h>
00032 #include <libintl.h>
00033 #include <iconv.h>
00034 #endif
00035
00044 static void SetUsername() {
00045 const char *str = NULL;
00046
00047 if ((str = getenv("USER")) == NULL) {
00048
00049 str = getenv("USERNAME");
00050 }
00051
00052 if ((str == NULL) || (str[0] == 0)) {
00053
00054 str = (char*)strings[STRING_DEFAULTNAME];
00055 }
00056 #ifdef USE_GETTEXT
00057 else {
00058
00059 #ifndef WIN32
00060 iconv_t descr = iconv_open("wchar_t", "");
00061 #else
00062 iconv_t descr = iconv_open("UTF-16LE", "");
00063 #endif
00064
00065 if (descr != (iconv_t)-1) {
00066 const char *src = str;
00067 wchar_t *dest = menuSettings->localPlayerName;
00068 size_t srcLen = strlen(str);
00069 size_t destLen = sizeof(menuSettings->localPlayerName) *
00070 sizeof(wchar_t);
00071 iconv(descr, (char**)&src, &srcLen, (char**)&dest, &destLen);
00072 *dest = 0;
00073 iconv_close(descr);
00074
00075 return;
00076 }
00077 }
00078 #endif
00079
00080 rtsa_strncpy(menuSettings->localPlayerName, (rtsa_char*)str,
00081 MAX_NAME_LEN - 1);
00082
00083 menuSettings->localPlayerName[MAX_NAME_LEN - 1] = 0;
00084 }
00085
00086 void GetLocalPlayerName(rtsa_char *dest) {
00087 assert(menuSettings != NULL);
00088
00089 if (menuSettings->localPlayerName[0] == 0) {
00090
00091 SetUsername();
00092 }
00093
00094 rtsa_strcpy(dest, menuSettings->localPlayerName);
00095 }
00096
00097 void SetLocalPlayerName(rtsa_char *name) {
00098 assert(menuSettings != NULL);
00099
00100 if ((name == NULL) || (name[0] == 0)) {
00101
00102 SetUsername();
00103 }
00104 else {
00105
00106 rtsa_strncpy(menuSettings->localPlayerName, name, MAX_NAME_LEN - 1);
00107
00108 menuSettings->localPlayerName[MAX_NAME_LEN - 1] = 0;
00109 }
00110 }
00111