public void SendEntityHashRequest(Guid entityGuid) { NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToServerMsgType.RequestEntityHash); msg.Write(entityGuid.ToByteArray()); NetClientObject.SendMessage(msg, NetClientObject.ServerConnection, NetDeliveryMethod.ReliableOrdered); }
void SendStringMessage(NetConnection recipient, string message) { NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToClientMsgType.SendStringMessage); msg.Write(message); NetServerObject.SendMessage(msg, recipient, NetDeliveryMethod.ReliableOrdered); }
public void SendSystemDataRequest(Guid systemID) { NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToServerMsgType.RequestSystemData); msg.Write(systemID.ToByteArray()); NetClientObject.SendMessage(msg, NetClientObject.ServerConnection, NetDeliveryMethod.ReliableOrdered); }
void SendDatablob(NetConnection recipient, Entity entity, BaseDataBlob datablob) { Messages.Add("Sending " + datablob.GetType().Name); NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToClientMsgType.SendDatablob); //message type NetServerObject.SendMessage(msg, recipient, NetDeliveryMethod.ReliableOrdered); }
void SendEntityData(NetConnection recipient, Entity entity) { NetOutgoingMessage sendMsg = NetPeerObject.CreateMessage(); sendMsg.Write((byte)ToClientMsgType.SendEntity); //receving it is the same as any normal entity. EntityDataMessage(sendMsg, entity); NetServerObject.SendMessage(sendMsg, recipient, NetDeliveryMethod.ReliableOrdered); SendEntityProcData(recipient, entity); }
void SendEntityCommandAck(NetConnection recipient, Guid cmdID, bool isValid) { NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToClientMsgType.SendEntityCommandAck); msg.Write(cmdID.ToByteArray()); msg.Write(isValid); Messages.Add("Sending " + isValid + " Command ack ID: " + cmdID); NetServerObject.SendMessage(msg, recipient, NetDeliveryMethod.ReliableOrdered); }
/// <summary> /// Sends the faction data request. and sets up a link between this connection and a faction. /// </summary> /// <param name="factionName">Faction.</param> /// <param name="password">Password.</param> public void SendFactionDataRequest(string factionName, string password) { NetOutgoingMessage sendMsg = NetPeerObject.CreateMessage(); sendMsg.Write((byte)ToServerMsgType.RequestFactionEntityData); sendMsg.Write(factionName); sendMsg.Write(password); Encrypt(sendMsg);//sequence channel 31 is expected to be encrypted by the recever. see NetworkBase GotMessage() NetClientObject.SendMessage(sendMsg, NetClientObject.ServerConnection, NetDeliveryMethod.ReliableOrdered, SecureChannel); }
public void SendDatablobRequest(Guid entityID, Type datablobType) { //TODO: datablobs have an int ID, can we use that? can we be sure that the server and client's datablob IDs are the same? NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToServerMsgType.RequestDatablob); msg.Write(entityID.ToByteArray()); //EntityID msg.Write(datablobType.Name); //type. msg.Write(EntityManager.DataBlobTypes[datablobType]); //typeIndex NetClientObject.SendMessage(msg, NetClientObject.ServerConnection, NetDeliveryMethod.ReliableOrdered); }
void SendEntityHashData(NetConnection recipient, Entity entity) { //TODO: check which thread is doing this, and at what time, this info should probilby be done by the managersubpulse thread at a specific time. MemoryStream mStream = new MemoryStream(); NetOutgoingMessage netMessage = NetPeerObject.CreateMessage(); netMessage.Write((byte)ToClientMsgType.SendEntityHashData); netMessage.Write(entity.Guid.ToByteArray()); //Entity ID netMessage.Write(entity.Manager.ManagerSubpulses.StarSysDateTime.ToBinary()); //Date netMessage.Write(entity.GetHashCode()); //Entity Hash netMessage.Write(entity.DataBlobs.Count); //NumberOfDatablobs foreach (IGetValuesHash item in entity.DataBlobs) // { netMessage.Write(item.GetType().ToString()); //Datablob Type Name netMessage.Write(item.GetValueCompareHash()); //Datablob Hash } NetServerObject.SendMessage(netMessage, recipient, NetDeliveryMethod.ReliableOrdered); }
void SendGameSettings(NetConnection recipient, Game game) { var gamesettings = game.Settings; var mStream = new MemoryStream(); SerializationManager.Export(game.Settings, mStream); byte[] byteArray = mStream.ToArray(); int len = byteArray.Length; NetOutgoingMessage sendMsg = NetPeerObject.CreateMessage(); sendMsg.Write((byte)ToClientMsgType.SendGameData); sendMsg.Write(StaticRefLib.CurrentDateTime.ToBinary()); sendMsg.Write(len); sendMsg.Write(byteArray); NetServerObject.SendMessage(sendMsg, recipient, NetDeliveryMethod.ReliableOrdered); }
void SendEntityProcData(NetConnection recipient, Entity entity) { NetOutgoingMessage msg = NetPeerObject.CreateMessage(); msg.Write((byte)ToClientMsgType.SendEntityProcData); var procDict = entity.Manager.ManagerSubpulses.GetInstanceProcForEntity(entity); var mStream = new MemoryStream(); SerializationManager.Export(procDict, mStream); byte[] procdicByteArray = mStream.ToArray(); int len = procdicByteArray.Length; msg.Write(entity.Guid.ToByteArray()); msg.Write(len); msg.Write(procdicByteArray); mStream.Close(); NetServerObject.SendMessage(msg, recipient, NetDeliveryMethod.ReliableOrdered); }
void SendEntityChangeData(List <NetConnection> recipients, EntityChangeData changeData) { NetOutgoingMessage message = NetPeerObject.CreateMessage(); message.Write((byte)ToClientMsgType.SendEntityChangeData); message.Write((byte)changeData.ChangeType); switch (changeData.ChangeType) { case EntityChangeData.EntityChangeType.EntityAdded: { EntityDataMessage(message, changeData.Entity); } break; case EntityChangeData.EntityChangeType.EntityRemoved: { message.Write(changeData.Entity.Guid.ToByteArray()); } break; case EntityChangeData.EntityChangeType.DBAdded: { DatablobDataMessage(message, changeData.Entity, changeData.Datablob); } break; case EntityChangeData.EntityChangeType.DBRemoved: { message.Write(changeData.Entity.Guid.ToByteArray()); //entity guid. message.Write(changeData.Datablob.GetType().Name); //datablob name message.Write(EntityManager.DataBlobTypes[changeData.Datablob.GetType()]); //datablob typeIndex } break; default: throw new Exception("Network classes need to handle EntityChangeType"); } foreach (var recipient in recipients) { NetServerObject.SendMessage(message, recipient, NetDeliveryMethod.ReliableOrdered); } Messages.Add("Sent " + changeData.ChangeType + " changeData to " + recipients.Count + " netclient."); }
void SendSystemData(NetConnection recipient, StarSystem starSystem) { Entity faction = Game.GlobalManager.GetGlobalEntityByGuid(_connectedFactions[recipient]); List <Entity> ownedEntitiesForSystem = starSystem.GetEntitiesByFaction(faction.Guid); var mStream = new MemoryStream(); NetOutgoingMessage sendMsg = NetPeerObject.CreateMessage(); sendMsg.Write((byte)ToClientMsgType.SendSystemData); sendMsg.Write(starSystem.Guid.ToByteArray()); NetServerObject.SendMessage(sendMsg, recipient, NetDeliveryMethod.ReliableOrdered); foreach (var entity in ownedEntitiesForSystem) { SendEntityData(recipient, entity); } }
public void SendEntityCommand(EntityCommand cmd) { Guid cmdID = Guid.NewGuid(); CommandsAwaitingServerAproval.Add(cmdID, cmd); NetOutgoingMessage sendMsg = NetPeerObject.CreateMessage(); var mStream = new MemoryStream(); SerializationManager.Export(Game, mStream, cmd); byte[] byteArray = mStream.ToArray(); int len = byteArray.Length; sendMsg.Write((byte)ToServerMsgType.SendPlayerEntityCommand); sendMsg.Write(cmdID.ToByteArray()); sendMsg.Write(cmd.GetType().Name); sendMsg.Write(len); sendMsg.Write(byteArray); NetClientObject.SendMessage(sendMsg, NetClientObject.ServerConnection, NetDeliveryMethod.ReliableOrdered); Messages.Add("Sent Command " + cmd.CmdID); }
void SendFactionHash(NetConnection recipient, Entity factionEntity) { ProtoEntity factionEntityClone = factionEntity.Clone(); //clone it, then remove the AuthDB, we don't send it, so don't include the hash for it. factionEntityClone.RemoveDataBlob <AuthDB>(); MemoryStream mStream = new MemoryStream(); NetOutgoingMessage netMessage = NetPeerObject.CreateMessage(); netMessage.Write((byte)ToClientMsgType.SendEntityHashData); List <BaseDataBlob> blobsWithValueHash = (List <BaseDataBlob>)factionEntityClone.DataBlobs.Where((arg) => arg is IGetValuesHash); netMessage.Write(blobsWithValueHash.Count); foreach (IGetValuesHash item in blobsWithValueHash) { netMessage.Write(item.GetType().ToString()); netMessage.Write(item.GetValueCompareHash()); } NetServerObject.SendMessage(netMessage, recipient, NetDeliveryMethod.ReliableOrdered); }
void SendFactionData(NetConnection recipient, Entity factionEntity) { //var ownedEntities = factionEntity.GetDataBlob<FactionOwnedEntitesDB>().OwnedEntites.Values.ToArray(); ProtoEntity factionEntityClone = factionEntity.Clone(); //clone it, then remove the AuthDB, we don't want to send that. factionEntityClone.RemoveDataBlob <AuthDB>(); var mStream = new MemoryStream(); SerializationManager.Export(Game, mStream, factionEntityClone); byte[] entityByteArray = mStream.ToArray(); int len = entityByteArray.Length; NetOutgoingMessage sendMsg = NetPeerObject.CreateMessage(); sendMsg.Write((byte)ToClientMsgType.SendFactionEntity); sendMsg.Write(factionEntity.Guid.ToByteArray()); sendMsg.Write(factionEntityClone.GetValueCompareHash()); sendMsg.Write(len); sendMsg.Write(entityByteArray); NetServerObject.SendMessage(sendMsg, recipient, NetDeliveryMethod.ReliableOrdered); mStream.Close(); }
public void HandleOrder(EntityCommand entityCommand) //TODO: maybe rename this since in the netclient and server 'HandleFoo' tends to represent handling a network message. (this is from the OrderHandler interface) { NetOutgoingMessage msg = NetPeerObject.CreateMessage(); SendEntityCommand(entityCommand); }