You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

414 lines
19 KiB

5 years ago
12 months ago
12 months ago
5 years ago
5 years ago
5 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
5 years ago
5 years ago
  1. use std::net::Ipv4Addr;
  2. use log::{info};
  3. use networking::interserver::AuthToken;
  4. use login_server::login::LoginServerState;
  5. use login_server::character::CharacterServerState;
  6. use patch_server::{PatchServerState, generate_patch_tree, load_config, load_motd};
  7. use elseware::ship::ship::ShipServerStateBuilder;
  8. use maps::Holiday;
  9. use entity::gateway::{EntityGateway, InMemoryGateway};
  10. use entity::account::{NewUserAccountEntity, NewUserSettingsEntity};
  11. use entity::character::NewCharacterEntity;
  12. use entity::item::{NewItemEntity, ItemDetail, InventoryItemEntity};
  13. use entity::item;
  14. fn setup_logger() {
  15. let colors = fern::colors::ColoredLevelConfig::new()
  16. .error(fern::colors::Color::Red)
  17. .warn(fern::colors::Color::Yellow)
  18. .info(fern::colors::Color::Green)
  19. .debug(fern::colors::Color::White)
  20. .trace(fern::colors::Color::BrightBlack);
  21. let stdio = fern::Dispatch::new()
  22. .level(log::LevelFilter::Debug)
  23. .format(move |out, message, record| {
  24. out.finish(format_args!(
  25. "\x1B[{}m[{}][{}][{}] {}\x1B[0m",
  26. colors.get_color(&record.level()).to_fg_str(),
  27. chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
  28. record.target(),
  29. record.level(),
  30. message,
  31. ))
  32. })
  33. .chain(std::io::stdout());
  34. let fileout = fern::Dispatch::new()
  35. .level(log::LevelFilter::Trace)
  36. .chain(fern::log_file(format!("log/elseware-{}.log", chrono::Local::now().format("%Y-%m-%d_%H-%M-%S"))).unwrap());
  37. fern::Dispatch::new()
  38. .chain(stdio)
  39. .chain(fileout)
  40. .apply().unwrap();
  41. }
  42. fn main() {
  43. setup_logger();
  44. async_std::task::block_on(async move {
  45. //let mut entity_gateway = PostgresGateway::new("localhost", "elsewhere", "elsewhere", "");
  46. let mut entity_gateway = InMemoryGateway::default();
  47. for i in 0..5 {
  48. let fake_user = NewUserAccountEntity {
  49. email: format!("fake{i}@email.com"),
  50. username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) },
  51. password: bcrypt::hash("qwer", 5).unwrap(),
  52. guildcard: i + 1,
  53. team_id: None,
  54. banned_until: None,
  55. muted_until: None,
  56. flags: 0,
  57. activated: true,
  58. };
  59. let fake_user = entity_gateway.create_user(fake_user).await.unwrap();
  60. entity_gateway.create_user_settings(NewUserSettingsEntity::new(fake_user.id)).await.unwrap();
  61. let mut character = NewCharacterEntity::new(fake_user.id);
  62. character.name = format!("Test Char {}", i*2);
  63. let character = entity_gateway.create_character(character).await.unwrap();
  64. entity_gateway.set_character_meseta(&character.id, item::Meseta(999999)).await.unwrap();
  65. entity_gateway.set_bank_meseta(&character.id, &item::BankIdentifier::Character, item::Meseta(999999)).await.unwrap();
  66. let mut character = NewCharacterEntity::new(fake_user.id);
  67. character.slot = 2;
  68. character.name = "ItemRefactor".into();
  69. character.exp = 80000000;
  70. let character = entity_gateway.create_character(character).await.unwrap();
  71. entity_gateway.set_character_meseta(&character.id, item::Meseta(999999)).await.unwrap();
  72. entity_gateway.set_bank_meseta(&character.id, &item::BankIdentifier::Character, item::Meseta(999999)).await.unwrap();
  73. for _ in 0..3 {
  74. entity_gateway.create_item(
  75. item::NewItemEntity {
  76. item: item::ItemDetail::Weapon(
  77. item::weapon::Weapon {
  78. weapon: item::weapon::WeaponType::Vulcan,
  79. grind: 0,
  80. special: None,
  81. attrs: [None, None, None],
  82. tekked: true,
  83. }
  84. ),
  85. }).await.unwrap();
  86. }
  87. for _ in 0..8 {
  88. entity_gateway.create_item(
  89. NewItemEntity {
  90. item: ItemDetail::Tool (
  91. item::tool::Tool {
  92. tool: item::tool::ToolType::Monomate,
  93. }
  94. ),
  95. }).await.unwrap();
  96. }
  97. let item0 = entity_gateway.create_item(
  98. NewItemEntity {
  99. item: ItemDetail::Weapon(
  100. item::weapon::Weapon {
  101. weapon: item::weapon::WeaponType::Raygun,
  102. grind: 5,
  103. special: Some(item::weapon::WeaponSpecial::Hell),
  104. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 40}),
  105. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}),
  106. None,],
  107. tekked: false,
  108. }
  109. ),
  110. }).await.unwrap();
  111. let item1 = entity_gateway.create_item(
  112. NewItemEntity {
  113. item: ItemDetail::Weapon(
  114. item::weapon::Weapon {
  115. weapon: item::weapon::WeaponType::Handgun,
  116. grind: 5,
  117. special: Some(item::weapon::WeaponSpecial::Charge),
  118. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 40}),
  119. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}),
  120. None,],
  121. tekked: true,
  122. }
  123. ),
  124. }).await.unwrap();
  125. let item2_w = entity_gateway.create_item(
  126. NewItemEntity {
  127. item: ItemDetail::Weapon(
  128. item::weapon::Weapon {
  129. weapon: item::weapon::WeaponType::Vjaya,
  130. grind: 5,
  131. special: Some(item::weapon::WeaponSpecial::Charge),
  132. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 40}),
  133. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  134. None,],
  135. tekked: true,
  136. }
  137. ),
  138. }).await.unwrap();
  139. let item3 = entity_gateway.create_item(
  140. NewItemEntity {
  141. item: ItemDetail::Weapon(
  142. item::weapon::Weapon {
  143. weapon: item::weapon::WeaponType::Vulcan,
  144. grind: 5,
  145. special: Some(item::weapon::WeaponSpecial::Charge),
  146. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  147. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  148. None,],
  149. tekked: true,
  150. }
  151. ),
  152. }).await.unwrap();
  153. let item4 = entity_gateway.create_item(
  154. NewItemEntity {
  155. item: ItemDetail::Weapon(
  156. item::weapon::Weapon {
  157. weapon: item::weapon::WeaponType::DarkFlow,
  158. grind: 0,
  159. special: None,
  160. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  161. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  162. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  163. tekked: true,
  164. }
  165. ),
  166. }).await.unwrap();
  167. let item5_m = entity_gateway.create_item(
  168. item::NewItemEntity {
  169. item: item::ItemDetail::Mag(item::mag::Mag::baby_mag(0)),
  170. }).await.unwrap();
  171. for _ in 0..10usize {
  172. let fed_tool = entity_gateway.create_item(
  173. NewItemEntity {
  174. item: ItemDetail::Tool (
  175. item::tool::Tool {
  176. tool: item::tool::ToolType::Monomate,
  177. }
  178. ),
  179. }).await.unwrap();
  180. entity_gateway.feed_mag(&item5_m.id, &fed_tool.id).await.unwrap();
  181. }
  182. entity_gateway.change_mag_owner(&item5_m.id, &character).await.unwrap();
  183. let item6 = entity_gateway.create_item(
  184. item::NewItemEntity {
  185. item: ItemDetail::Tool (
  186. item::tool::Tool {
  187. tool: item::tool::ToolType::CellOfMag502,
  188. }
  189. ),
  190. }).await.unwrap();
  191. let cell = entity_gateway.create_item(
  192. item::NewItemEntity {
  193. item: ItemDetail::Tool (
  194. item::tool::Tool {
  195. tool: item::tool::ToolType::CellOfMag502,
  196. }
  197. ),
  198. }).await.unwrap();
  199. entity_gateway.use_mag_cell(&item5_m.id, &cell.id).await.unwrap();
  200. let item6_1 = entity_gateway.create_item(
  201. NewItemEntity {
  202. item: ItemDetail::ESWeapon(
  203. item::esweapon::ESWeapon::new(item::esweapon::ESWeaponType::Saber)
  204. ),
  205. }).await.unwrap();
  206. let item7_a = entity_gateway.create_item(
  207. NewItemEntity {
  208. item: ItemDetail::Armor(
  209. item::armor::Armor {
  210. armor: item::armor::ArmorType::Frame,
  211. dfp: 2,
  212. evp: 2,
  213. slots: 4,
  214. }
  215. ),
  216. }
  217. ).await.unwrap();
  218. let item8_s = entity_gateway.create_item(
  219. NewItemEntity {
  220. item: ItemDetail::Shield(
  221. item::shield::Shield {
  222. shield: item::shield::ShieldType::Barrier,
  223. dfp: 5,
  224. evp: 5,
  225. }
  226. ),
  227. }
  228. ).await.unwrap();
  229. let item9_u0 = entity_gateway.create_item(
  230. NewItemEntity {
  231. item: ItemDetail::Unit(
  232. item::unit::Unit {
  233. unit: item::unit::UnitType::PriestMind,
  234. modifier: Some(item::unit::UnitModifier::PlusPlus),
  235. }
  236. ),
  237. }
  238. ).await.unwrap();
  239. let item10_u1 = entity_gateway.create_item(
  240. NewItemEntity {
  241. item: ItemDetail::Unit(
  242. item::unit::Unit {
  243. unit: item::unit::UnitType::PriestMind,
  244. modifier: Some(item::unit::UnitModifier::Plus),
  245. }
  246. ),
  247. }
  248. ).await.unwrap();
  249. let item11_u2 = entity_gateway.create_item(
  250. NewItemEntity {
  251. item: ItemDetail::Unit(
  252. item::unit::Unit {
  253. unit: item::unit::UnitType::PriestMind,
  254. modifier: Some(item::unit::UnitModifier::Minus),
  255. }
  256. ),
  257. }
  258. ).await.unwrap();
  259. let item12_u3 = entity_gateway.create_item(
  260. NewItemEntity {
  261. item: ItemDetail::Unit(
  262. item::unit::Unit {
  263. unit: item::unit::UnitType::PriestMind,
  264. modifier: Some(item::unit::UnitModifier::MinusMinus),
  265. }
  266. ),
  267. }
  268. ).await.unwrap();
  269. let item13 = entity_gateway.create_item(
  270. NewItemEntity {
  271. item: ItemDetail::Mag(
  272. item::mag::Mag::baby_mag(5)
  273. ),
  274. }
  275. ).await.unwrap();
  276. let item14 = entity_gateway.create_item(
  277. NewItemEntity {
  278. item: ItemDetail::Weapon(
  279. item::weapon::Weapon {
  280. weapon: item::weapon::WeaponType::Vulcan,
  281. grind: 5,
  282. special: Some(item::weapon::WeaponSpecial::Charge),
  283. attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
  284. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}),
  285. Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),],
  286. tekked: true,
  287. }
  288. ),
  289. }).await.unwrap();
  290. let monomates = futures::future::join_all((0..6).map(|_| {
  291. let mut entity_gateway = entity_gateway.clone();
  292. async move {
  293. entity_gateway.create_item(
  294. NewItemEntity {
  295. item: ItemDetail::Tool (
  296. item::tool::Tool {
  297. tool: item::tool::ToolType::Monomate,
  298. }
  299. ),
  300. }).await.unwrap()
  301. }
  302. })).await;
  303. let equipped = item::EquippedEntity {
  304. weapon: Some(item2_w.id),
  305. armor: Some(item7_a.id),
  306. shield: Some(item8_s.id),
  307. unit: [Some(item9_u0.id), Some(item10_u1.id), Some(item11_u2.id), Some(item12_u3.id)],
  308. mag: Some(item5_m.id),
  309. };
  310. entity_gateway.set_character_equips(&character.id, &equipped).await.unwrap();
  311. let inventory = item::InventoryEntity::new(vec![InventoryItemEntity::from(item0), item1.into(), item2_w.into(), item3.into(),
  312. item4.into(), item5_m.into(), item6.into(), item6_1.into(), item7_a.into(),
  313. item8_s.into(), item9_u0.into(), item10_u1.into(), item11_u2.into(), item12_u3.into(),
  314. item13.into(), item14.into(), monomates.into()]);
  315. entity_gateway.set_character_inventory(&character.id, &inventory).await.unwrap();
  316. entity_gateway.set_character_bank(&character.id, &item::BankEntity::default(), &item::BankIdentifier::Character).await.unwrap();
  317. }
  318. info!("[patch] starting server");
  319. let patch_config = load_config();
  320. let patch_motd = load_motd();
  321. let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str());
  322. let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd);
  323. let patch_loop = async_std::task::spawn(async move {
  324. networking::mainloop::run_server(patch_state, patch_config.port).await;
  325. });
  326. info!("[auth] starting server");
  327. let login_state = LoginServerState::new(entity_gateway.clone(), "127.0.0.1".parse().unwrap());
  328. let login_loop = async_std::task::spawn(async move {
  329. networking::mainloop::run_server(login_state, login_server::login::LOGIN_PORT).await;
  330. });
  331. info!("[character] starting server");
  332. let char_state = CharacterServerState::new(entity_gateway.clone(), AuthToken("".into()));
  333. let sub_char_state = char_state.clone();
  334. let character_loop = async_std::task::spawn(async move {
  335. networking::mainloop::run_server(sub_char_state, login_server::character::CHARACTER_PORT).await;
  336. });
  337. let sub_char_state = char_state.clone();
  338. let inter_character_loop = async_std::task::spawn(async move {
  339. networking::mainloop::run_interserver_listen(sub_char_state, login_server::login::COMMUNICATION_PORT).await;
  340. });
  341. info!("[ship] starting servers");
  342. let ship_state = ShipServerStateBuilder::default()
  343. .name("US/Sona-Nyl".into())
  344. .ip(Ipv4Addr::new(127,0,0,1))
  345. .port(elseware::ship::ship::SHIP_PORT)
  346. .event(Holiday::Halloween)
  347. .gateway(entity_gateway.clone())
  348. .build();
  349. let sub_ship_state = ship_state.clone();
  350. let ship_loop1 = async_std::task::spawn(async move {
  351. networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT).await;
  352. });
  353. let sub_ship_state = ship_state.clone();
  354. let inter_ship_loop1 = async_std::task::spawn(async move {
  355. networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await;
  356. });
  357. let ship_state = ShipServerStateBuilder::default()
  358. .name("EU/Dylath-Leen".into())
  359. .ip(Ipv4Addr::new(127,0,0,1))
  360. .port(elseware::ship::ship::SHIP_PORT+2000)
  361. .event(Holiday::Christmas)
  362. .gateway(entity_gateway.clone())
  363. .build();
  364. let sub_ship_state = ship_state.clone();
  365. let ship_loop2 = async_std::task::spawn(async move {
  366. networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT+2000).await;
  367. });
  368. let sub_ship_state = ship_state.clone();
  369. let inter_ship_loop2 = async_std::task::spawn(async move {
  370. networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await;
  371. });
  372. let ship_state = ShipServerStateBuilder::default()
  373. .name("JP/Thalarion".into())
  374. .ip(Ipv4Addr::new(127,0,0,1))
  375. .port(elseware::ship::ship::SHIP_PORT+3000)
  376. .gateway(entity_gateway.clone())
  377. .build();
  378. let sub_ship_state = ship_state.clone();
  379. let ship_loop3 = async_std::task::spawn(async move {
  380. networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT+3000).await;
  381. });
  382. let sub_ship_state = ship_state.clone();
  383. let inter_ship_loop3 = async_std::task::spawn(async move {
  384. networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await;
  385. });
  386. futures::future::join_all(vec![patch_loop, login_loop, character_loop, inter_character_loop,
  387. ship_loop1, ship_loop2, ship_loop3,
  388. inter_ship_loop1, inter_ship_loop2, inter_ship_loop3]).await;
  389. });
  390. }