public void disconnect(MessageOut msg) { if(isConnected()) { mPeer.Close(); } }
public void sendCharacterData(Character p) { MessageOut msg=new MessageOut(Protocol.GAMSG_PLAYER_DATA); msg.writeInt32(p.getDatabaseID()); p.serializeCharacterData(msg); send(msg); }
public void deletePendingClient(NetComputer client) { MessageOut msg=new MessageOut(Protocol.CPMSG_CONNECT_RESPONSE); msg.writeInt8((int)ErrorMessage.ERRMSG_TIME_OUT); // The computer will be deleted when the disconnect event is processed client.disconnect(msg); }
public void addUser(string name, string inviter) { mUsers.Add(name); for(int i=0; i<userCount(); ++i) { MessageOut outmsg=new MessageOut(Protocol.CPMSG_PARTY_NEW_MEMBER); outmsg.writeString(name); outmsg.writeString(inviter); Program.chatHandler.getClient(mUsers[i]).send(outmsg); } }
public void disconnect(MessageOut msg) { if(isConnected()) { ///* ChannelID 0xFF is the channel used by enet_peer_disconnect. // * If a reliable packet is send over this channel ENet guaranties // * that the message is recieved before the disconnect request. // */ //send(msg, ENET_PACKET_FLAG_RELIABLE, 0xFF); ///* ENet generates a disconnect event // * (notifying the connection handler). // */ //enet_peer_disconnect(mPeer, 0); } }
int mSyncMessages; /**< Number of messages in the sync buffer. */ #endregion Fields #region Constructors public AccountConnection() { mSyncBuffer=new MessageOut(); mSyncMessages=0; }
void playerReconnectAccount(int id, string magic_token) { Logger.Write(LogLevel.Debug, "Send GAMSG_PLAYER_RECONNECT."); MessageOut msg=new MessageOut(Protocol.GAMSG_PLAYER_RECONNECT); msg.writeInt32(id); msg.writeString(magic_token); send(msg); }
void updateMapVar(MapComposite map, string name, string value) { MessageOut msg=new MessageOut(Protocol.GAMSG_SET_VAR_MAP); msg.writeInt32(map.getID()); msg.writeString(name); msg.writeString(value); send(msg); }
void updateWorldVar(string name, string @value) { MessageOut msg=new MessageOut(Protocol.GAMSG_SET_VAR_WORLD); msg.writeString(name); msg.writeString(@value); send(msg); }
public static bool insert(Thing ptr) { //assert(!dbgLockObjects); MapComposite map=ptr.getMap(); //assert(map && map.isActive()); /* Non-visible objects have neither position nor public ID, so their insertion cannot fail. Take care of them first. */ if(!ptr.isVisible()) { map.insert(ptr); ptr.inserted(); return true; } // Check that coordinates are actually valid. Actor obj=(Actor)ptr; Map mp=map.getMap(); Point pos=obj.getPosition(); if((int)pos.x/mp.getTileWidth()>=mp.getWidth()|| (int)pos.y/mp.getTileHeight()>=mp.getHeight()) { Logger.Write(LogLevel.Error, "Tried to insert an actor at position {0}, {1} outside map {2}.", pos.x, pos.y, map.getID()); // Set an arbitrary small position. pos=new Point(100, 100); obj.setPosition(pos); } if(!map.insert(obj)) { // The map is overloaded, no room to add a new actor Logger.Write(LogLevel.Error, "Too many actors on map {0}.", map.getID()); return false; } obj.inserted(); // DEBUG INFO //TODO Implementieren // switch(obj.getType()) // { // case ThingType.OBJECT_ITEM: // Logger.Write(LogLevel.Debug, "Item inserted: " // (Item)(obj).getItemClass().getDatabaseID()); // break; // // case ThingType.OBJECT_NPC: // Logger.Write(LogLevel.Debug, "NPC inserted: "<<static_cast<NPC*>(obj).getNPC()); // break; // // case ThingType.OBJECT_CHARACTER: // Logger.Write(LogLevel.Debug, "Player inserted: " // <<static_cast<Being*>(obj).getName()); // break; // // case ThingType.OBJECT_EFFECT: // Logger.Write(LogLevel.Debug, "Effect inserted: " // <<static_cast<Effect*>(obj).getEffectId()); // break; // // case ThingType.OBJECT_MONSTER: // Logger.Write(LogLevel.Debug, "Monster inserted: " // <<static_cast<Monster*>(obj).getSpecy().getId()); // break; // // case ThingType.OBJECT_ACTOR: // case ThingType.OBJECT_OTHER: // default: // Logger.Write(LogLevel.Debug, "Thing inserted: "<<obj.getType()); // } obj.raiseUpdateFlags((byte)UpdateFlag.UPDATEFLAG_NEW_ON_MAP); if(obj.getType()!=ThingType.OBJECT_CHARACTER) return true; /* Since the player does not know yet where in the world its character is, we send a map-change message, even if it is the first time it connects to this server. */ MessageOut mapChangeMessage=new MessageOut(Protocol.GPMSG_PLAYER_MAP_CHANGE); mapChangeMessage.writeString(map.getName()); mapChangeMessage.writeInt16(pos.x); mapChangeMessage.writeInt16(pos.y); Program.gameHandler.sendTo((Character)(obj), mapChangeMessage); // update the online state of the character Program.accountHandler.updateOnlineStatus(((Character)obj).getDatabaseID(), true); return true; }
public void serializeCharacterData(MessageOut msg) { // general character properties msg.writeInt8(getAccountLevel()); msg.writeInt8((int)getGender()); msg.writeInt8(getHairStyle()); msg.writeInt8(getHairColor()); msg.writeInt16(getLevel()); msg.writeInt16(getCharacterPoints()); msg.writeInt16(getCorrectionPoints()); msg.writeInt16(mAttributes.Count); // foreach(KeyValuePair<uint, AttributeValue> pair in mAttributes) // { // msg.writeInt16((Int16)pair.Key); // // msg.writeDouble(pair.Value.@base); // msg.writeDouble(pair.Value.modified); // } foreach(KeyValuePair<uint, Attribute> pair in mAttributes) { msg.writeInt16((int)pair.Key); msg.writeDouble(pair.Value.getBase()); msg.writeDouble(pair.Value.getModifiedAttribute()); } // character skills msg.writeInt16(getSkillSize()); foreach(KeyValuePair<int, int> pair in mExperience) { msg.writeInt16(pair.Key); msg.writeInt32(pair.Value); } // status effects currently affecting the character msg.writeInt16(getStatusEffectSize()); foreach(KeyValuePair<int, int> pair in mStatusEffects) { msg.writeInt16(pair.Key); msg.writeInt16(pair.Value); } // location msg.writeInt16(getMapId()); Point pos=getPosition(); msg.writeInt16(pos.x); msg.writeInt16(pos.y); // kill count msg.writeInt16(getKillCountSize()); foreach(KeyValuePair<int, int> pair in mKillCount) { msg.writeInt16(pair.Key); msg.writeInt32(pair.Value); } // character specials msg.writeInt16(mSpecials.Count); foreach(KeyValuePair<int, Special> pair in mSpecials) { msg.writeInt32(pair.Key); } // inventory - must be last because size isn't transmitted Possessions poss=getPossessions(); Dictionary< uint, EquipmentItem > equipData=poss.getEquipment(); msg.writeInt16(equipData.Count); // number of equipment foreach(KeyValuePair<uint, EquipmentItem> k in equipData) { msg.writeInt16((int)k.Key); // Equip slot id msg.writeInt16((int)k.Value.itemId); // ItemId msg.writeInt16((int)k.Value.itemInstance); // Item Instance id } Dictionary< uint, InventoryItem > inventoryData=poss.getInventory(); foreach(KeyValuePair<uint, InventoryItem> j in inventoryData) { msg.writeInt16((int)j.Key); // slot id msg.writeInt16((int)j.Value.itemId); // item id msg.writeInt16((int)j.Value.amount); // amount } }
public void send(MessageOut msg, bool reliable, uint channel) { Logger.Write(LogLevel.Debug, "Sending message {0} to {1}", msg, this); //gBandwidth.increaseClientOutput(this, msg.getLength()); NetworkStream stream=mPeer.GetStream(); //Länge senden ushort lengthPackage=(ushort)msg.getLength(); byte[] lengthAsByteArray=BitConverter.GetBytes(lengthPackage); stream.Write(lengthAsByteArray, 0, (int)lengthAsByteArray.Length); //TODO Überprüfung ob Länge größer ushort dann Problem stream.Write(msg.getData(), 0, (int)msg.getLength()); //if(packet) //{ // enet_peer_send(mPeer, channel, packet); //} //else //{ // LOG_ERROR("Failure to create packet!"); //} }
protected void sendToEveryone(MessageOut msg) { foreach(NetComputer comp in clients) { comp.send(msg); } }
public static void registerGameClient(GameServer s, string token, Character ptr) { MessageOut msg=new MessageOut(Protocol.AGMSG_PLAYER_ENTER); msg.writeString(token); msg.writeInt32(ptr.getDatabaseID()); msg.writeString(ptr.getName()); ptr.serializeCharacterData(msg); s.send(msg); }
// internal GameServer getGameServerFromMap(int); //internal void GameServerHandler::dumpStatistics(std::ostream &); /// <summary> /// Processes server messages. /// </summary> /// <param name="computer"></param> /// <param name="message"></param> protected override void processMessage(NetComputer computer, MessageIn message) { MessageOut result=new MessageOut(); GameServer server=(GameServer)(computer); switch(message.getId()) { case Protocol.GAMSG_REGISTER: { Logger.Write(LogLevel.Debug, "GAMSG_REGISTER"); // TODO: check the credentials of the game server server.address=message.readString(); server.port=message.readInt16(); string password=message.readString(); // checks the version of the remote item database with our local copy uint dbversion=(uint)message.readInt32(); Logger.Write(LogLevel.Information, "Game server uses itemsdatabase with version {0}", dbversion); Logger.Write(LogLevel.Debug, "AGMSG_REGISTER_RESPONSE"); MessageOut outmessage=new MessageOut(Protocol.AGMSG_REGISTER_RESPONSE); if(dbversion==Program.storage.getItemDatabaseVersion()) { Logger.Write(LogLevel.Debug, "Item databases between account server and gameserver are in sync"); outmessage.writeInt16((int)DataVersion.DATA_VERSION_OK); } else { Logger.Write(LogLevel.Debug, "Item database of game server has a wrong version"); outmessage.writeInt16((int)DataVersion.DATA_VERSION_OUTDATED); } if(password==Configuration.getValue("net_password", "changeMe")) { outmessage.writeInt16((int)Password.PASSWORD_OK); computer.send(outmessage); // transmit global world state variables Dictionary<string, string> variables; variables=Program.storage.getAllWorldStateVars(0); foreach(KeyValuePair<string, string> pair in variables) { outmessage.writeString(pair.Key); outmessage.writeString(pair.Value); } } else { Logger.Write(LogLevel.Information, "The password given by {0}:{1} was bad.", server.address, server.port); outmessage.writeInt16((int)Password.PASSWORD_BAD); computer.disconnect(outmessage); break; } Logger.Write(LogLevel.Information, "Game server {0}:{1} wants to register {2} maps.", server.address, server.port, (message.getUnreadLength()/2)); while(message.getUnreadLength()!=0) { int id=message.readInt16(); Logger.Write(LogLevel.Information, "Registering map {0}.", id); GameServer s=GameServerHandler.getGameServerFromMap(id); if(s!=null) { Logger.Write(LogLevel.Error, "Server Handler: map is already registered by {0}:{1}.", s.address, s.port); } else { MessageOut tmpOutMsg=new MessageOut(Protocol.AGMSG_ACTIVE_MAP); // Map variables tmpOutMsg.writeInt16(id); Dictionary<string, string> variables; variables=Program.storage.getAllWorldStateVars(id); // Map vars number tmpOutMsg.writeInt16(variables.Count); foreach(KeyValuePair<string, string> pair in variables) { tmpOutMsg.writeString(pair.Key); tmpOutMsg.writeString(pair.Value); } // Persistent Floor Items List<FloorItem> items=Program.storage.getFloorItemsFromMap(id); tmpOutMsg.writeInt16(items.Count); //number of floor items // Send each map item: item_id, amount, pos_x, pos_y foreach(FloorItem i in items) { tmpOutMsg.writeInt32(i.getItemId()); tmpOutMsg.writeInt16(i.getItemAmount()); tmpOutMsg.writeInt16(i.getPosX()); tmpOutMsg.writeInt16(i.getPosY()); } computer.send(tmpOutMsg); //MapStatistics m=server.maps[(ushort)id]; //Auskommentiert da nicht klar ist wo dieser Wert gesetzt wird //m.nbThings=0; //m.nbMonsters=0; } } } break; case Protocol.GAMSG_PLAYER_DATA: { Logger.Write(LogLevel.Debug, "GAMSG_PLAYER_DATA"); int id=message.readInt32(); try { Character ptr=Program.storage.getCharacter(id, null); CharacterData.deserializeCharacterData(ptr, message); if(!Program.storage.updateCharacter(ptr)) { Logger.Write(LogLevel.Error, "Failed to update character {0}.", id); } } catch { Logger.Write(LogLevel.Error, "Received data for non-existing character {0}.", id); } } break; case Protocol.GAMSG_PLAYER_SYNC: { Logger.Write(LogLevel.Debug, "GAMSG_PLAYER_SYNC"); GameServerHandler.syncDatabase(message); } break; case Protocol.GAMSG_REDIRECT: { Logger.Write(LogLevel.Debug, "GAMSG_REDIRECT"); int id=message.readInt32(); //string magic_token(utils::getMagicToken()); string magic_token=Various.GetUniqueID(); try { Character ptr=Program.storage.getCharacter(id, null); int mapId=ptr.getMapId(); try { GameServer s=GameServerHandler.getGameServerFromMap(mapId); GameServerHandler.registerGameClient(s, magic_token, ptr); result.writeInt16((int)Protocol.AGMSG_REDIRECT_RESPONSE); result.writeInt32(id); result.writeString(magic_token); result.writeString(s.address); result.writeInt16(s.port); } catch { Logger.Write(LogLevel.Error, "Server Change: No game server for map {0}.", mapId); } } catch { Logger.Write(LogLevel.Error, "Received data for non-existing character {0}.", id); } } break; case Protocol.GAMSG_PLAYER_RECONNECT: { Logger.Write(LogLevel.Debug, "GAMSG_PLAYER_RECONNECT"); int id=message.readInt32(); string magic_token=message.readString(); //string magic_token=message.readString(ManaServ.MAGIC_TOKEN_LENGTH); try { Character ptr=Program.storage.getCharacter(id, null); int accountID=ptr.getAccountID(); AccountClientHandler.prepareReconnect(magic_token, accountID); } catch { Logger.Write(LogLevel.Error, "Received data for non-existing character {0}.", id); } } break; case Protocol.GAMSG_GET_VAR_CHR: { int id=message.readInt32(); string name=message.readString(); string value=Program.storage.getQuestVar(id, name); result.writeInt16((Int16)Protocol.AGMSG_GET_VAR_CHR_RESPONSE); result.writeInt32(id); result.writeString(name); result.writeString(value); } break; case Protocol.GAMSG_SET_VAR_CHR: { int id=message.readInt32(); string name=message.readString(); string value=message.readString(); Program.storage.setQuestVar(id, name, value); } break; case Protocol.GAMSG_SET_VAR_WORLD: { string name=message.readString(); string value=message.readString(); // save the new value to the database Program.storage.setWorldStateVar(name, value); // relay the new value to all gameservers foreach(NetComputer client in clients) { MessageOut varUpdateMessage=new MessageOut(Protocol.AGMSG_SET_VAR_WORLD); varUpdateMessage.writeString(name); varUpdateMessage.writeString(value); client.send(varUpdateMessage); } } break; case Protocol.GAMSG_SET_VAR_MAP: { int mapid=message.readInt32(); string name=message.readString(); string value=message.readString(); Program.storage.setWorldStateVar(name, mapid, value); } break; case Protocol.GAMSG_BAN_PLAYER: { int id=message.readInt32(); int duration=message.readInt32(); Program.storage.banCharacter(id, duration); } break; case Protocol.GAMSG_CHANGE_PLAYER_LEVEL: { int id=message.readInt32(); int level=message.readInt16(); Program.storage.setPlayerLevel(id, level); } break; case Protocol.GAMSG_CHANGE_ACCOUNT_LEVEL: { int id=message.readInt32(); int level=message.readInt16(); // get the character so we can get the account id Character c=Program.storage.getCharacter(id, null); if(c!=null) { Program.storage.setAccountLevel(c.getAccountID(), level); } } break; case Protocol.GAMSG_STATISTICS: { //while (message.getUnreadLength()!=0) //{ // int mapId = message.readInt16(); // ServerStatistics::iterator i = server.maps.find(mapId); // if (i == server.maps.end()) // { // Logger.Add(LogLevel.Error, "Server {0}:{1} should not be sending statistics for map {2}.", server.address, server.port, mapId); // // Skip remaining data. // break; // } // MapStatistics m = i.second; // m.nbThings =(ushort) message.readInt16(); // m.nbMonsters=(ushort)message.readInt16(); // int nb = message.readInt16(); // m.players.resize(nb); // for (int j = 0; j < nb; ++j) // { // m.players[j] = message.readInt32(); // } //} } break; case Protocol.GCMSG_REQUEST_POST: { // Retrieve the post for user Logger.Write(LogLevel.Debug, "GCMSG_REQUEST_POST"); result.writeInt16((int)Protocol.CGMSG_POST_RESPONSE); // get the character id int characterId=message.readInt32(); // send the character id of sender result.writeInt32(characterId); // get the character based on the id Character ptr=Program.storage.getCharacter(characterId, null); if(ptr!=null) { // Invalid character Logger.Write(LogLevel.Error, "Error finding character id for post"); break; } // get the post for that character Post post=Program.postalManager.getPost(ptr); // send the post if valid if(post!=null) { for(int i=0; i<post.getNumberOfLetters(); ++i) { // get each letter, send the sender's name, // the contents and any attachments Letter letter=post.getLetter(i); result.writeString(letter.getSender().getName()); result.writeString(letter.getContents()); List<InventoryItem> items=letter.getAttachments(); for(uint j=0; j<items.Count; ++j) { result.writeInt16((int)items[(int)j].itemId); result.writeInt16((int)items[(int)j].amount); } } // clean up Program.postalManager.clearPost(ptr); } } break; case Protocol.GCMSG_STORE_POST: { //// Store the letter for the user //Logger.Add(LogLevel.Debug, "GCMSG_STORE_POST"); //result.writeInt16((int)Protocol.CGMSG_STORE_POST_RESPONSE); //// get the sender and receiver //int senderId = message.readInt32(); //string receiverName = message.readString(); //// for sending it back //result.writeInt32(senderId); //// get their characters //Character sender = Program.storage.getCharacter(senderId, null); //Character receiver=Program.storage.getCharacter(receiverName); //if (sender!=null || receiver!=null) //{ // // Invalid character // Logger.Add(LogLevel.Error, "Error finding character id for post"); // result.writeInt8(ManaServ.ERRMSG_INVALID_ARGUMENT); // break; //} //// get the letter contents //string contents = message.readString(); //List<Pair<int>> items; //while (message.getUnreadLength()!=0) //{ // items.Add(new Pair<int>(message.readInt16(), message.readInt16())); //} //// save the letter //Logger.Add(LogLevel.Debug, "Creating letter"); //Letter letter = new Letter(0, sender, receiver); //letter.addText(contents); //for (uint i = 0; i < items.Count; ++i) //{ // InventoryItem item; // item.itemId = items[i].first; // item.amount = items[i].second; // letter.addAttachment(item); //} //Program.postalManager.addLetter(letter); //result.writeInt8(ManaServ.ERRMSG_OK); } break; case Protocol.GAMSG_TRANSACTION: { Logger.Write(LogLevel.Debug, "TRANSACTION"); int id=message.readInt32(); int action=message.readInt32(); string messageS=message.readString(); Transaction trans=new Transaction(); trans.mCharacterId=(uint)id; trans.mAction=(uint)action; trans.mMessage=messageS; Program.storage.addTransaction(trans); } break; case Protocol.GCMSG_PARTY_INVITE: Program.chatHandler.handlePartyInvite(message); break; case Protocol.GAMSG_CREATE_ITEM_ON_MAP: { int mapId=message.readInt32(); int itemId=message.readInt32(); int amount=message.readInt16(); int posX=message.readInt16(); int posY=message.readInt16(); Logger.Write(LogLevel.Debug, "Gameserver create item {0} on map {1} ", itemId, mapId); Program.storage.addFloorItem(mapId, itemId, amount, posX, posY); } break; case Protocol.GAMSG_REMOVE_ITEM_ON_MAP: { int mapId=message.readInt32(); int itemId=message.readInt32(); int amount=message.readInt16(); int posX=message.readInt16(); int posY=message.readInt16(); Logger.Write(LogLevel.Debug, "Gameserver removed item {0} from map {1}", itemId, mapId); Program.storage.removeFloorItem(mapId, itemId, amount, posX, posY); } break; default: { Logger.Write(LogLevel.Warning, "ServerHandler::processMessage, Invalid message type: {0}", message.getId()); result.writeInt16((int)Protocol.XXMSG_INVALID); break; } } // return result if(result.getLength()>0) { computer.send(result); } }
void getPost(Character c) { // let the postman know to expect some post for this character Program.postMan.addCharacter(c); // send message to account server with id of retrieving player Logger.Write(LogLevel.Debug, "Sending GCMSG_REQUEST_POST"); MessageOut outmsg=new MessageOut(Protocol.GCMSG_REQUEST_POST); outmsg.writeInt32(c.getDatabaseID()); send(outmsg); }
void changeAccountLevel(Character c, int level) { MessageOut msg=new MessageOut(Protocol.GAMSG_CHANGE_ACCOUNT_LEVEL); msg.writeInt32(c.getDatabaseID()); msg.writeInt16(level); send(msg); }
void banCharacter(Character ch, int duration) { MessageOut msg=new MessageOut(Protocol.GAMSG_BAN_PLAYER); msg.writeInt32(ch.getDatabaseID()); msg.writeInt32(duration); send(msg); }
public void syncChanges(bool force) { if(mSyncMessages==0) return; // send buffer if: // a.) forced by any process // b.) every 10 seconds // c.) buffer reaches size of 1kb // d.) buffer holds more then 20 messages if(force|| mSyncMessages>SYNC_BUFFER_LIMIT|| mSyncBuffer.getLength()>SYNC_BUFFER_SIZE) { Logger.Write(LogLevel.Debug, "Sending GAMSG_PLAYER_SYNC with {0} messages.", mSyncMessages); send(mSyncBuffer); mSyncBuffer=new MessageOut(Protocol.GAMSG_PLAYER_SYNC); mSyncMessages=0; } else { Logger.Write(LogLevel.Debug, "No changes to sync with account server."); } }
public bool start(int gameServerPort) { string accountServerAddress=Configuration.getValue("net_accountHost", "localhost"); // When the accountListenToGamePort is set, we use it. // Otherwise, we use the accountListenToClientPort + 1 if the option is set. // If neither, the DEFAULT_SERVER_PORT + 1 is used. int alternativePort=Configuration.getValue("net_accountListenToClientPort", 0)+1; if(alternativePort==1) alternativePort=Configuration.DEFAULT_SERVER_PORT+1; int accountServerPort=Configuration.getValue("net_accountListenToGamePort", alternativePort); if(!start(accountServerAddress, accountServerPort)) { Logger.Write(LogLevel.Information, "Unable to create a connection to an account server."); return false; } Logger.Write(LogLevel.Information, "Connection established to the account server."); string gameServerAddress=Configuration.getValue("net_gameHost", "localhost"); string password=Configuration.getValue("net_password", "changeMe"); // Register with the account server and send the list of maps we handle MessageOut msg=new MessageOut(Protocol.GAMSG_REGISTER); msg.writeString(gameServerAddress); msg.writeInt16(gameServerPort); msg.writeString(password); msg.writeInt32((int)Program.itemManager.getDatabaseVersion()); Dictionary<int, MapComposite> m=MapManager.getMaps(); foreach(int map in m.Keys) { msg.writeInt16(map); } send(msg); // initialize sync buffer if(mSyncBuffer==null) mSyncBuffer=new MessageOut(Protocol.GAMSG_PLAYER_SYNC); return true; }
public static void sendPartyChange(Character ptr, int partyId) { GameServer s=getGameServerFromMap(ptr.getMapId()); if(s!=null) { MessageOut msg=new MessageOut(Protocol.CGMSG_CHANGED_PARTY); msg.writeInt32(ptr.getDatabaseID()); msg.writeInt32(partyId); s.send(msg); } }
void removeFloorItems(int mapId, int itemId, int amount, int posX, int posY) { MessageOut msg=new MessageOut(Protocol.GAMSG_REMOVE_ITEM_ON_MAP); msg.writeInt32(mapId); msg.writeInt32(itemId); msg.writeInt16(amount); msg.writeInt16(posX); msg.writeInt16(posY); send(msg); }
public void send(MessageOut msg) { send(msg, true, 0); }
void requestCharacterVar(Character ch, string name) { MessageOut msg=new MessageOut(Protocol.GAMSG_GET_VAR_CHR); msg.writeInt32(ch.getDatabaseID()); msg.writeString(name); send(msg); }
//, bool reliable, uint channel) //TODO Connection zu Netcomputer zusammenfassen? public void send(MessageOut msg) { NetworkStream stream=mRemote.GetStream(); //Länge senden ushort lengthPackage=(ushort)msg.getLength(); byte[] lengthAsByteArray=BitConverter.GetBytes(lengthPackage); stream.Write(lengthAsByteArray, 0, (int)lengthAsByteArray.Length); stream.Write(msg.getData(), 0, (int)msg.getLength()); //if (!mRemote) { // LOG_WARN("Can't send message to unconnected host! (" << msg << ")"); // return; //} //gBandwidth.increaseInterServerOutput(msg.getLength()); //ENetPacket *packet; //packet = enet_packet_create(msg.getData(), // msg.getLength(), // reliable ? ENET_PACKET_FLAG_RELIABLE : 0); //if (packet) // enet_peer_send(mRemote, channel, packet); //else // LOG_ERROR("Failure to create packet!"); }
void sendPost(Character c, MessageIn msg) { // send message to account server with id of sending player, // the id of receiving player, the letter receiver and contents, and attachments Logger.Write(LogLevel.Debug, "Sending GCMSG_STORE_POST."); MessageOut outmsg=new MessageOut(Protocol.GCMSG_STORE_POST); outmsg.writeInt32(c.getDatabaseID()); outmsg.writeString(msg.readString()); // name of receiver outmsg.writeString(msg.readString()); // content of letter while(msg.getUnreadLength()>0) // attachments { // write the item id and amount for each attachment outmsg.writeInt32(msg.readInt16()); outmsg.writeInt32(msg.readInt16()); } send(outmsg); }
/** * Sets message fields describing character look. */ static void serializeLooks(Character ch, MessageOut msg, bool full) { //const Possessions &poss = ch.getPossessions(); //unsigned int nb_slots = itemManager.getVisibleSlotCount(); //// Bitmask describing the changed entries. //int changed = (1 << nb_slots) - 1; //if (!full) //{ // // TODO: do not assume the whole equipment changed, // // when an update is asked for. // changed = (1 << nb_slots) - 1; //} //std::vector<unsigned int> items; //items.resize(nb_slots, 0); //// Partially build both kinds of packet, to get their sizes. //unsigned int mask_full = 0, mask_diff = 0; //unsigned int nb_full = 0, nb_diff = 0; //std::map<unsigned int, unsigned int>::const_iterator it = // poss.equipSlots.begin(); //for (unsigned int i = 0; i < nb_slots; ++i) //{ // if (changed & (1 << i)) // { // // Skip slots that have not changed, when sending an update. // ++nb_diff; // mask_diff |= 1 << i; // } // if (it == poss.equipSlots.end() || it.first > i) continue; // ItemClass *eq; // items[i] = it.first && (eq = itemManager.getItem(it.first)) ? // eq.getSpriteID() : 0; // if (items[i]) // { // /* If we are sending the whole equipment, only filled slots have to // be accounted for, as the other ones will be automatically cleared. */ // ++nb_full; // mask_full |= 1 << i; // } //} //// Choose the smaller payload. //if (nb_full <= nb_diff) full = true; ///* Bitmask enumerating the sent slots. // Setting the upper bit tells the client to clear the slots beforehand. */ //int mask = full ? mask_full | (1 << 7) : mask_diff; //msg.writeInt8(mask); //for (unsigned int i = 0; i < nb_slots; ++i) //{ // if (mask & (1 << i)) msg.writeInt16(items[i]); //} }
void sendTransaction(int id, int action, string message) { MessageOut msg=new MessageOut(Protocol.GAMSG_TRANSACTION); msg.writeInt32(id); msg.writeInt32(action); msg.writeString(message); send(msg); }
static void warp(Character ptr, MapComposite map, int x, int y) { //TODO DEBUG555 entfernen int debug=555; remove(ptr); ptr.setMap(map); ptr.setPosition(new Point(x, y)); ptr.clearDestination(); /* Force update of persistent data on map change, so that characters can respawn at the start of the map after a death or a disconnection. */ Program.accountHandler.sendCharacterData(ptr); if(map.isActive()) { if(!insert(ptr)) { ptr.disconnected(); Program.gameHandler.kill(ptr); } } else { MessageOut msg=new MessageOut(Protocol.GAMSG_REDIRECT); msg.writeInt32(ptr.getDatabaseID()); Program.accountHandler.send(msg); Program.gameHandler.prepareServerChange(ptr); } }
void updateCharacterVar(Character ch, string name, string value) { MessageOut msg=new MessageOut(Protocol.GAMSG_SET_VAR_CHR); msg.writeInt32(ch.getDatabaseID()); msg.writeString(name); msg.writeString(value); send(msg); }