move message packet handlers
This commit is contained in:
		
							parent
							
								
									832a53821d
								
							
						
					
					
						commit
						0b04701156
					
				
							
								
								
									
										48
									
								
								src/ship/packet/handler/direct_message.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/ship/packet/handler/direct_message.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| use std::collections::HashMap; | ||||
| use log::warn; | ||||
| use libpso::packet::ship::*; | ||||
| use libpso::packet::messages::*; | ||||
| use crate::common::serverstate::ClientId; | ||||
| use crate::common::leveltable::CharacterLevelTable; | ||||
| use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Rooms}; | ||||
| use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; | ||||
| use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; | ||||
| use libpso::character::character; | ||||
| use crate::entity::gateway::EntityGateway; | ||||
| use libpso::{utf8_to_array, utf8_to_utf16_array}; | ||||
| 
 | ||||
| fn send_to_client(id: ClientId, target: u8, msg: DirectMessage, client_location: &ClientLocation) | ||||
|                   -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> { | ||||
|     Box::new(client_location.get_all_clients_by_client(id).unwrap().into_iter() | ||||
|              .filter(move |client| client.local_client.id() == target) | ||||
|              .map(move |client| { | ||||
|                  (client.client, SendShipPacket::DirectMessage(msg.clone())) | ||||
|              })) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| pub fn guildcard_send(id: ClientId, | ||||
|                       guildcard_send: &GuildcardSend, | ||||
|                       target: u32, | ||||
|                       client_location: &ClientLocation, | ||||
|                       clients: &HashMap<ClientId, ClientState>) | ||||
|                       -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> { | ||||
|     let client = clients.get(&id).unwrap(); | ||||
|     let msg = DirectMessage{ | ||||
|         flag: target, | ||||
|         msg: GameMessage::GuildcardRecv(GuildcardRecv { | ||||
|             client: guildcard_send.client, | ||||
|             target: guildcard_send.target, | ||||
|             guildcard: client.user.id.0, | ||||
|             name: utf8_to_utf16_array!(client.character.name, 0x18), | ||||
|             team: [0; 0x10], // TODO: teams not yet implemented
 | ||||
|             desc: utf8_to_utf16_array!(client.character.guildcard.description, 0x58), | ||||
|             one: 1, | ||||
|             language: 0, // TODO: add language flag to character
 | ||||
|             section_id: client.character.section_id.into(), | ||||
|             class: client.character.char_class.into(), | ||||
|         }), | ||||
|     }; | ||||
|     send_to_client(id, target as u8, msg, &client_location) | ||||
| } | ||||
							
								
								
									
										27
									
								
								src/ship/packet/handler/message.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/ship/packet/handler/message.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| use std::collections::HashMap; | ||||
| use log::warn; | ||||
| use libpso::packet::ship::*; | ||||
| use libpso::packet::messages::*; | ||||
| use crate::common::serverstate::ClientId; | ||||
| use crate::common::leveltable::CharacterLevelTable; | ||||
| use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Rooms}; | ||||
| use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; | ||||
| use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; | ||||
| use libpso::character::character; | ||||
| use crate::entity::gateway::EntityGateway; | ||||
| 
 | ||||
| pub fn request_exp(id: ClientId, | ||||
|                    request_exp: &RequestExp, | ||||
|                    client_location: &ClientLocation, | ||||
|                    rooms: &Rooms) | ||||
|                    -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> { | ||||
|     
 | ||||
|     match client_location.get_area(id).unwrap() { | ||||
|         RoomLobby::Room(room) => { | ||||
|             let r  = rooms[room.0].as_ref().unwrap(); | ||||
|             warn!("killed a {:?}", r.maps.enemy_by_id(request_exp.enemy_id as usize).monster); | ||||
|         }, | ||||
|         _ => {} | ||||
|     }; | ||||
|     Box::new(None.into_iter()) | ||||
| } | ||||
| @ -1,5 +1,7 @@ | ||||
| pub mod auth; | ||||
| pub mod communication; | ||||
| pub mod direct_message; | ||||
| pub mod lobby; | ||||
| pub mod message; | ||||
| pub mod room; | ||||
| pub mod settings; | ||||
|  | ||||
| @ -210,73 +210,29 @@ impl<EG: EntityGateway> ShipServerState<EG> { | ||||
| 
 | ||||
|     fn message(&mut self, id: ClientId, msg: &Message) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> { | ||||
|         match &msg.msg { | ||||
|             GameMessage::RequestExp(killmonster) => { | ||||
|                 match self.client_location.get_area(id).unwrap() { | ||||
|                     RoomLobby::Room(room) => { | ||||
|                         let r  = self.rooms[room.0].as_ref().unwrap(); | ||||
|                         warn!("killed a {:?}", r.maps.enemy_by_id(killmonster.enemy_id as usize).monster); | ||||
|                     }, | ||||
|                     _ => {} | ||||
|                 } | ||||
|             GameMessage::RequestExp(request_exp) => { | ||||
|                 handler::message::request_exp(id, request_exp, &self.client_location, &self.rooms) | ||||
|             }, | ||||
|             _ => { | ||||
|                 let cmsg = msg.clone(); | ||||
|                 Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter() | ||||
|                     .map(move |client| { | ||||
|                         (client.client, SendShipPacket::Message(cmsg.clone())) | ||||
|                     })) | ||||
|             }, | ||||
|             _ => {}, | ||||
|         } | ||||
| 
 | ||||
|         let cmsg = msg.clone(); | ||||
|         Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter() | ||||
|                  .map(move |client| { | ||||
|                      (client.client, SendShipPacket::Message(cmsg.clone())) | ||||
|                  })) | ||||
|     } | ||||
| 
 | ||||
|     fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> { | ||||
|         let cmsg = msg.clone(); | ||||
|         let client = self.clients.get_mut(&id).unwrap(); | ||||
|         match &cmsg.msg { | ||||
|         let target = msg.flag; | ||||
|         match &msg.msg { | ||||
|             GameMessage::GuildcardSend(guildcard_send) => { | ||||
|                 let out_msg = DirectMessage{ | ||||
|                     flag: cmsg.flag, | ||||
|                     msg: GameMessage::GuildcardRecv(GuildcardRecv { | ||||
|                         client: guildcard_send.client, | ||||
|                         target: guildcard_send.target, | ||||
|                         guildcard: client.user.id.0, | ||||
|                         name: utf8_to_utf16_array!(client.character.name, 0x18), | ||||
|                         team: [0; 0x10], // TODO: teams not yet implemented
 | ||||
|                         desc: utf8_to_utf16_array!(client.character.guildcard.description, 0x58), | ||||
|                         one: 1, | ||||
|                         language: 0, // TODO: add language flag to character
 | ||||
|                         section_id: client.character.section_id.into(), | ||||
|                         class: client.character.char_class.into(), | ||||
|                     }), | ||||
|                 }; | ||||
|                 let msg_flag = cmsg.flag as u8; | ||||
|                 Box::new(self.client_location.get_all_clients_by_client(id).unwrap().into_iter() | ||||
|                     .filter(move |client| client.local_client.id() == msg_flag) | ||||
|                     .map(move |client| { | ||||
|                         (client.client, SendShipPacket::DirectMessage(out_msg.clone())) | ||||
|                     })) | ||||
|                 handler::direct_message::guildcard_send(id, guildcard_send, target, &self.client_location, &self.clients) | ||||
|             }, | ||||
|             /*GameMessage::RequestItem(req_item) => {
 | ||||
|                 let item = self.generate_item_drop(id); | ||||
|                 Box::new(vec![(id, SendShipPacket::Message(Message::new(GameMessage::ItemDrop(ItemDrop { | ||||
|                     client: req_item.client, | ||||
|                     target: req_item.target, | ||||
|                     area: req_item.area, | ||||
|                     variety: 0, | ||||
|                     unknown: 0, | ||||
|                     x: req_item.x, | ||||
|                     z: req_item.z, | ||||
|                     unknown2: 0, | ||||
|                     item_bytes: item[0..12].try_into().unwrap(), | ||||
|                     item_id: 0, | ||||
|                     item_bytes2: item[12..16].try_into().unwrap(), | ||||
|                     unknown3: 0, | ||||
|                 }))))].into_iter()) | ||||
|             },*/ | ||||
|             _ => { | ||||
|                 let msg_flag = cmsg.flag as u8; | ||||
|                 let cmsg = msg.clone(); | ||||
|                 Box::new(self.client_location.get_all_clients_by_client(id).unwrap().into_iter() | ||||
|                     .filter(move |client| client.local_client.id() == msg_flag) | ||||
|                     .filter(move |client| client.local_client.id() == target as u8) | ||||
|                     .map(move |client| { | ||||
|                         (client.client, SendShipPacket::DirectMessage(cmsg.clone())) | ||||
|                     })) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user