Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite ship design with same ID #2913

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions universe/Universe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ bool Universe::InsertShipDesignID(ShipDesign* ship_design, boost::optional<int>
return false;
}

if (m_ship_designs.count(id)) {
ErrorLogger() << "Ship design id " << id << " already exists.";
return false;
}
ship_design->SetID(id);
m_ship_designs[id] = ship_design;
return true;
Expand Down
6 changes: 5 additions & 1 deletion util/Order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,9 +1204,13 @@ void ShipDesignOrder::ExecuteImpl() const {
// On the client create a new design id
universe.InsertShipDesign(new_ship_design);
m_design_id = new_ship_design->ID();
DebugLogger() << "ShipDesignOrder::ExecuteImpl Create new ship design ID " << m_design_id;
} else {
// On the server use the design id passed from the client
universe.InsertShipDesignID(new_ship_design, EmpireID(), m_design_id);
if (!universe.InsertShipDesignID(new_ship_design, EmpireID(), m_design_id)) {
ErrorLogger() << "Couldn't insert ship design by ID " << m_design_id;
return;
}
}

universe.SetEmpireKnowledgeOfShipDesign(m_design_id, EmpireID());
Expand Down