Changeset 433
- Timestamp:
- May 7, 2023, 5:05:29 PM (20 months ago)
- Location:
- binary-improvements2
- Files:
-
- 3 added
- 9 edited
- 12 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/WebServer.csproj
r432 r433 120 120 <Compile Include="src\WebAPI\AbsRestApi.cs" /> 121 121 <Compile Include="src\WebAPI\AbsWebAPI.cs" /> 122 <Compile Include="src\WebAPI\APIs\Animal.cs" />123 122 <Compile Include="src\WebAPI\APIs\Command.cs" /> 124 <Compile Include="src\WebAPI\APIs\GetLandClaims.cs" /> 125 <Compile Include="src\WebAPI\APIs\GetPlayerInventories.cs" /> 126 <Compile Include="src\WebAPI\APIs\GetPlayerInventory.cs" /> 127 <Compile Include="src\WebAPI\APIs\GetPlayerList.cs" /> 128 <Compile Include="src\WebAPI\APIs\GetPlayersLocation.cs" /> 129 <Compile Include="src\WebAPI\APIs\GetPlayersOnline.cs" /> 130 <Compile Include="src\WebAPI\APIs\Hostile.cs" /> 131 <Compile Include="src\WebAPI\APIs\Item.cs" /> 123 <Compile Include="src\WebAPI\APIs\GameData\Item.cs" /> 124 <Compile Include="src\WebAPI\APIs\GameData\Mods.cs" /> 132 125 <Compile Include="src\WebAPI\APIs\Log.cs" /> 133 <Compile Include="src\WebAPI\APIs\Player.cs" /> 134 <Compile Include="src\WebAPI\APIs\RegisterUser.cs" /> 126 <Compile Include="src\WebAPI\APIs\Permissions\RegisterUser.cs" /> 135 127 <Compile Include="src\WebAPI\APIs\ServerInfo.cs" /> 136 128 <Compile Include="src\WebAPI\APIs\ServerStats.cs" /> 137 <Compile Include="src\WebAPI\APIs\Mods.cs" />138 129 <Compile Include="src\WebAPI\APIs\WebUiUpdates.cs" /> 130 <Compile Include="src\WebAPI\APIs\WorldState\Animal.cs" /> 131 <Compile Include="src\WebAPI\APIs\WorldState\GetLandClaims.cs" /> 132 <Compile Include="src\WebAPI\APIs\WorldState\GetPlayerInventories.cs" /> 133 <Compile Include="src\WebAPI\APIs\WorldState\GetPlayerInventory.cs" /> 134 <Compile Include="src\WebAPI\APIs\WorldState\GetPlayerList.cs" /> 135 <Compile Include="src\WebAPI\APIs\WorldState\GetPlayersLocation.cs" /> 136 <Compile Include="src\WebAPI\APIs\WorldState\GetPlayersOnline.cs" /> 137 <Compile Include="src\WebAPI\APIs\WorldState\Hostile.cs" /> 138 <Compile Include="src\WebAPI\APIs\WorldState\Player.cs" /> 139 139 <Compile Include="src\WebAPI\JsonCommons.cs" /> 140 140 <Compile Include="src\WebAPI\Null.cs" /> -
binary-improvements2/WebServer/src/Permissions/AdminWebUsers.cs
r404 r433 133 133 } 134 134 135 public WebUser? GetUser (string _name, string _password) {136 if (users.TryGetValue (_name, out WebUser user) && user.ValidatePassword (_password)) {137 return user;135 public bool TryGetUser (string _name, string _password, out WebUser _result) { 136 if (users.TryGetValue (_name, out _result) && _result.ValidatePassword (_password)) { 137 return true; 138 138 } 139 139 140 return null; 140 _result = default; 141 return false; 141 142 } 142 143 144 public bool HasUser (PlatformUserIdentifierAbs _platformUser, PlatformUserIdentifierAbs _crossPlatformUser, out WebUser _result) { 145 _result = default; 146 147 foreach ((string _, WebUser webUser) in users) { 148 if (!PlatformUserIdentifierAbs.Equals (webUser.PlatformUser, _platformUser) || 149 !PlatformUserIdentifierAbs.Equals (webUser.CrossPlatformUser, _crossPlatformUser)) { 150 continue; 151 } 143 152 144 #region Specials 153 _result = webUser; 154 return true; 155 } 145 156 146 147 #endregion 157 return false; 158 } 159 148 160 } 149 161 } -
binary-improvements2/WebServer/src/UrlHandlers/SessionHandler.cs
r422 r433 90 90 } 91 91 92 AdminWebUsers.WebUser? webUser = AdminWebUsers.Instance.GetUser (username, password); 93 94 if (!webUser.HasValue) { 92 if (!AdminWebUsers.Instance.TryGetUser (username, password, out AdminWebUsers.WebUser webUser)) { 95 93 Log.Out ($"[Web] User/pass login failed from {_remoteEndpointString}"); 96 94 WebUtils.WriteText (_context.Response, "UserPassInvalid", HttpStatusCode.Unauthorized); … … 98 96 } 99 97 100 HandleUserIdLogin (connectionHandler, _context, _remoteEndpointString, userPassLoginName, userPassErrorPage, webUser. Value.Name, webUser.Value.PlatformUser, webUser.Value.CrossPlatformUser);98 HandleUserIdLogin (connectionHandler, _context, _remoteEndpointString, userPassLoginName, userPassErrorPage, webUser.Name, webUser.PlatformUser, webUser.CrossPlatformUser); 101 99 } 102 100 -
binary-improvements2/WebServer/src/WebAPI/APIs/Permissions/RegisterUser.cs
r432 r433 79 79 return; 80 80 } 81 82 if (AdminWebUsers.Instance.GetUsers ().TryGetValue (username, out AdminWebUsers.WebUser existingMapping)) { 83 // Username already exists 84 85 if (!PlatformUserIdentifierAbs.Equals (existingMapping.PlatformUser, regData.PlatformUserId) || 86 !PlatformUserIdentifierAbs.Equals (existingMapping.CrossPlatformUser, regData.CrossPlatformUserId)) { 87 // Username already in use by another player 88 SendErrorResult (_context, HttpStatusCode.Unauthorized, _jsonInputData, "DUPLICATE_USERNAME"); 89 return; 90 } 91 92 // Username used by the same player, allow overwriting his existing login 93 } 81 94 82 // TODO: Check if username is already used by someone else! 83 // TODO: Remove existing username if player already had one! 95 // Log info 96 string crossplatformidString = regData.CrossPlatformUserId == null ? "" : $", crossplatform ID {regData.CrossPlatformUserId.CombinedString}"; 97 global::Log.Out ($"[Web] User registered: Username '{username}' for platform ID {regData.PlatformUserId.CombinedString}{crossplatformidString}"); 84 98 99 if (AdminWebUsers.Instance.HasUser (regData.PlatformUserId, regData.CrossPlatformUserId, out AdminWebUsers.WebUser existingUser)) { 100 // Remove existing username of player, only allowing one user per player 101 102 global::Log.Out ($"[Web] Re-registration, replacing existing username '{existingUser.Name}'"); 103 AdminWebUsers.Instance.RemoveUser (existingUser.Name); 104 } 105 106 // Add new user 85 107 AdminWebUsers.Instance.AddUser (username, password, regData.PlatformUserId, regData.CrossPlatformUserId); 86 108 109 // Login with new user and return response 87 110 string remoteEndpointString = _context.Request.RemoteEndPoint!.ToString (); 88 111 SessionHandler.HandleUserIdLogin (ParentWeb.ConnectionHandler, _context, remoteEndpointString, SessionHandler.userPassLoginName, … … 93 116 _context.Response.ContentEncoding = Encoding.UTF8; 94 117 _context.Response.ContentLength64 = 0; 95 // _context.Response.OutputStream.Write (jsonData.Array!, 0, jsonData.Count);96 118 } 97 119
Note:
See TracChangeset
for help on using the changeset viewer.