Skip to content

Commit

Permalink
TM 3.7.5 and 4.1.2 now build with old build tool, wait for free slot …
Browse files Browse the repository at this point in the history
…after starting StarCraft for clients
  • Loading branch information
Bytekeeper committed Apr 30, 2022
1 parent eb3ffea commit d0b5885
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions bots/template/bot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#race="Terran"
#race="Protoss"
#race="Zerg"
#race="Random"

# Path of bot executable (if not automatically detected)
#executable='bwapi-data\AI\ExampleAIModule.dll'
Expand Down
18 changes: 14 additions & 4 deletions src/bwapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,27 @@ impl GameTableAccess {
.map(|shmem| unsafe { *(shmem.as_ptr() as *const GameTable) })
}

pub fn get_connected_client_count(&mut self) -> usize {
pub fn all_slots_filled(&mut self) -> bool {
self.get_game_table()
.map(|table| {
// eprintln!("{:#?}", table);
!table
.game_instances
.iter()
.any(|it| it.server_process_id != 0 && !it.is_connected)
})
.unwrap_or(false)
}

pub fn has_free_slot(&mut self) -> bool {
self.get_game_table()
.map(|table| {
table
.game_instances
.iter()
.filter(|it| it.is_connected)
.count()
.any(|it| it.server_process_id != 0 && !it.is_connected)
})
.unwrap_or(0)
.unwrap_or(false)
}
}

Expand Down
20 changes: 11 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,6 @@ fn main() -> anyhow::Result<()> {
);
host = false;

let old_connected_client_count =
if matches!(bot.binary, Binary::Exe(_) | Binary::Dll(_)) {
game_table_access.get_connected_client_count()
} else {
0
};
let mut cmd = bwapi_launcher.build_command(&game_config)?;
cmd.stdout(File::create(bot.log_dir.join("game_out.log"))?)
.stderr(File::create(bot.log_dir.join("game_err.log"))?);
Expand Down Expand Up @@ -564,6 +558,15 @@ fn main() -> anyhow::Result<()> {
Binary::Exe(exe) => Some(sandbox.wrap_executable(exe)),
}
.map(|ref mut cmd| -> anyhow::Result<Child> {
// Wait for server to be ready to accept connections
retry(Fixed::from_millis(100).take(100), || {
if game_table_access.has_free_slot() {
OperationResult::Ok(())
} else {
OperationResult::Retry("Server process not ready")
}
}).map_err(|e| anyhow!(e))?;

cmd.current_dir(bot.working_dir);
cmd.stdout(bot_out_log);
cmd.stderr(bot_err_log);
Expand All @@ -572,13 +575,12 @@ fn main() -> anyhow::Result<()> {

// Wait up to 10 seconds before bailing
retry(Fixed::from_millis(100).take(100), || {
let found = game_table_access.get_connected_client_count()
> old_connected_client_count;
let slots_filled = game_table_access.all_slots_filled();
if !matches!(bwapi_child.try_wait(), Ok(None)) {
OperationResult::Err("BWAPI process died")
} else if !matches!(child.try_wait(), Ok(None)) {
OperationResult::Err("Bot process died")
} else if found {
} else if slots_filled {
OperationResult::Ok(())
} else {
OperationResult::Retry(
Expand Down
2 changes: 2 additions & 0 deletions tm/Custom Tournament Modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Just compile for each BWAPI version you like to support and add them here.
Be sure to name them <prefix>_<bwapiversion>.dll and use the prefix in the 'bot.toml' files
Binary file modified tm/TM_375.dll
Binary file not shown.
Binary file modified tm/TM_412.dll
Binary file not shown.
1 change: 1 addition & 0 deletions tm/Where are these from
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All TMs here are from https://github.com/basil-ladder/sc-tm - and are build by AppVeyor.

0 comments on commit d0b5885

Please sign in to comment.