|
832 | 832 | a: Array Of Integer; |
833 | 833 | b: Boolean; |
834 | 834 | Begin |
835 | | - log('TServer.HandleSwitchToMapProperties', llTrace); |
| 835 | + log(format('TServer.HandleSwitchToMapProperties (UID=%d)', [UID]), llInfo); |
836 | 836 | aicnt := 0; |
837 | 837 | pcnt := 0; |
838 | 838 | t1 := 0; |
|
1214 | 1214 | Procedure TServer.HandlePlaySoundEffect(PlayerIndex: integer; |
1215 | 1215 | Effect: TSoundEffect); |
1216 | 1216 | Var |
1217 | | - m: TMemoryStream; |
| 1217 | + m, m2: TMemoryStream; |
| 1218 | + targetUID: Integer; |
| 1219 | + i: Integer; |
| 1220 | + playerUID: Integer; |
1218 | 1221 | Begin |
1219 | 1222 | log('TServer.HandlePlaySoundEffect', llTrace); |
| 1223 | + // Check if player is valid |
| 1224 | + If (PlayerIndex < 0) Or (PlayerIndex > high(fPLayer)) Then Begin |
| 1225 | + log('Invalid PlayerIndex: ' + inttostr(PlayerIndex), llError); |
| 1226 | + LogLeave; |
| 1227 | + exit; |
| 1228 | + End; |
| 1229 | + |
| 1230 | + playerUID := fPLayer[PlayerIndex].UID; |
| 1231 | + |
| 1232 | + // Skip inactive slots (UID = NoPlayer = 0) |
| 1233 | + If playerUID = NoPlayer Then Begin |
| 1234 | + log('Skipping sound for inactive player slot: ' + inttostr(PlayerIndex), llTrace); |
| 1235 | + LogLeave; |
| 1236 | + exit; |
| 1237 | + End; |
| 1238 | + |
1220 | 1239 | m := TMemoryStream.Create; |
1221 | 1240 | m.Write(Effect, sizeof(Effect)); |
1222 | | - If Effect = seOtherPlayerDied Then Begin |
1223 | | - SendChunk(miPlaySoundEffekt, m, -fPLayer[PlayerIndex].UID); |
| 1241 | + |
| 1242 | + // Handle AI players (UID = AIPlayer = -1) - send sounds to all other players |
| 1243 | + If playerUID = AIPlayer Then Begin |
| 1244 | + // For AI players, send sounds to all connected players (broadcast) |
| 1245 | + // Use negative UID to indicate broadcast to all except sender (but sender is AI, so send to all) |
| 1246 | + If GetActivePlayerCount() > 0 Then Begin |
| 1247 | + // Send to all connected players (UID > 0) |
| 1248 | + targetUID := 0; // 0 means broadcast to all connected players |
| 1249 | + // Actually, we need to send to each connected player individually |
| 1250 | + // because SendChunk with negative UID excludes the sender, but we want to include all |
| 1251 | + For i := 0 To high(fPLayer) Do Begin |
| 1252 | + If fPLayer[i].UID > 0 Then Begin |
| 1253 | + // Create a new stream for each player |
| 1254 | + m2 := TMemoryStream.Create; |
| 1255 | + m2.Write(Effect, sizeof(Effect)); |
| 1256 | + SendChunk(miPlaySoundEffekt, m2, fPLayer[i].UID); |
| 1257 | + End; |
| 1258 | + End; |
| 1259 | + m.Free; // Free the original stream |
| 1260 | + End |
| 1261 | + Else Begin |
| 1262 | + log('Skipping AI sound - no connected players', llInfo); |
| 1263 | + m.Free; |
| 1264 | + End; |
| 1265 | + End |
| 1266 | + Else If playerUID > 0 Then Begin |
| 1267 | + // Normal player (UID > 0) |
| 1268 | + If Effect = seOtherPlayerDied Then Begin |
| 1269 | + // Send to all players except this one (broadcast with negative UID) |
| 1270 | + // Only send if there are at least 2 active players |
| 1271 | + If GetActivePlayerCount() > 1 Then Begin |
| 1272 | + targetUID := -playerUID; |
| 1273 | + SendChunk(miPlaySoundEffekt, m, targetUID); |
| 1274 | + End |
| 1275 | + Else Begin |
| 1276 | + log('Skipping seOtherPlayerDied sound - only one player connected', llInfo); |
| 1277 | + m.Free; |
| 1278 | + End; |
| 1279 | + End |
| 1280 | + Else Begin |
| 1281 | + // Send to this specific player |
| 1282 | + targetUID := playerUID; |
| 1283 | + SendChunk(miPlaySoundEffekt, m, targetUID); |
| 1284 | + End; |
1224 | 1285 | End |
1225 | 1286 | Else Begin |
1226 | | - SendChunk(miPlaySoundEffekt, m, fPLayer[PlayerIndex].UID); |
| 1287 | + // Unknown UID value |
| 1288 | + log('Unknown player UID: ' + inttostr(playerUID) + ' for player index: ' + inttostr(PlayerIndex), llWarning); |
| 1289 | + m.Free; |
1227 | 1290 | End; |
1228 | 1291 | LogLeave; |
1229 | 1292 | End; |
|
1372 | 1435 | j, i: Integer; |
1373 | 1436 | k: TKeySet; |
1374 | 1437 | Begin |
1375 | | - log('TServer.RefreshAllPlayerStats', llTrace); |
1376 | 1438 | m := TMemoryStream.Create; |
1377 | 1439 | // Einfügen aller Spielerinformationen, dass diese übernommen werden können (z.B. nach Load Game) |
1378 | 1440 | j := length(fPLayer); |
|
1389 | 1451 | m.WriteAnsiString(fPLayer[i].UserName); |
1390 | 1452 | End; |
1391 | 1453 | SendChunk(miRefreshPlayerStats, m, UID); |
1392 | | - LogLeave; |
1393 | 1454 | End; |
1394 | 1455 |
|
1395 | 1456 | Procedure TServer.PlayerLeaves(PlayerUid: integer); |
|
2012 | 2073 | exit; |
2013 | 2074 | End; |
2014 | 2075 | If AiInit() Then Begin |
2015 | | - log(format('Ai "%s" loaded..', [AiVersion()]), llInfo); |
| 2076 | + logshow(format('Ai "%s" loaded successfully!', [AiVersion()]), llInfo); |
2016 | 2077 | End |
2017 | 2078 | Else Begin |
2018 | | - log('Failure on Ai load.', llInfo); |
| 2079 | + logshow('Failure on Ai load (AiInit returned false).', llError); |
2019 | 2080 | UnLoadAiLib; |
2020 | 2081 | End; |
2021 | 2082 | If fGameState = gsPlaying Then Begin |
|
2096 | 2157 | // Egal, welcher Speedup, das Spiel wird mit konstanter Rate Aktualisiert |
2097 | 2158 | If fLastClientUpdateTimestamp + UpdateRate <= n Then Begin |
2098 | 2159 | fLastClientUpdateTimestamp := n; // fLastClientUpdateTimestamp + UpdateRate; Verhindern von oben beschriebener Situation |
2099 | | - UpdateAllClients; |
| 2160 | + // Only send updates if there are connected clients |
| 2161 | + If GetActivePlayerCount() > 0 Then Begin |
| 2162 | + UpdateAllClients; |
| 2163 | + End; |
2100 | 2164 | End; |
2101 | 2165 | End; |
2102 | 2166 | End; |
|
0 commit comments