public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int vobCount = 0; stream.Read(out vobCount); List <Vob> vobList = new List <Vob>(); for (int i = 0; i < vobCount; i++) { int vobID = 0; Vec3f pos, dir; stream.Read(out vobID); stream.Read(out pos); stream.Read(out dir); if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[vobID]; vob.Position = pos; vob.Direction = dir; vobList.Add(vob); } Write(vobList, packet.systemAddress); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client) { int callBackID = 0, playerID = 0; String section, entry; stream.Read(out callBackID); stream.Read(out playerID); stream.Read(out section); stream.Read(out entry); String value = ""; try { value = zCOption.GetOption(Process.ThisProcess()).getEntryValue(section, entry); } catch (Exception ex) {} stream.Reset(); stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.ReadIniEntryMessage); stream.Write(callBackID); stream.Write(playerID); stream.Write(section); stream.Write(entry); stream.Write(value); Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int casterID = 0; stream.Read(out casterID); Vob casterVob = null; NPCProto caster = null; sWorld.VobDict.TryGetValue(casterID, out casterVob); if (casterVob == null) { throw new Exception("Caster was not found!"); } if (!(casterVob is NPCProto)) { throw new Exception("Caster was not a npcproto " + casterVob); } caster = (NPCProto)casterVob; Write(caster, packet.guid); }
private static bool UpdateState(RakNet.BitStream stream) { bool isX = false; stream.Read(out isX); return(isX); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client) { int callBackID = 0, npcID = 0, vobID = 0; stream.Read(out callBackID); stream.Read(out npcID); stream.Read(out vobID); if (!sWorld.VobDict.ContainsKey(npcID) || !sWorld.VobDict.ContainsKey(vobID)) { throw new Exception("Vob or NPC weren't in the List!"); } NPCProto proto = (NPCProto)sWorld.VobDict[npcID]; Vob vob = (Vob)sWorld.VobDict[vobID]; bool canSee = false; if (proto.Address != 0 && vob.Address == 0) { canSee = (new oCNpc(Process.ThisProcess(), proto.Address).CanSee(new zCVob(Process.ThisProcess(), vob.Address), 0) == 1) ? true : false; } stream.Reset(); stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.CallbackNPCCanSee); stream.Write(callBackID); stream.Write(proto.ID); stream.Write(vob.ID); stream.Write(canSee); Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { String heroName = ""; String driveString = ""; String macString = ""; Vec3f pos = new Vec3f(); stream.Read(out heroName); stream.Read(out driveString); stream.Read(out macString); stream.Read(out pos); Player player = new Player(packet.guid, heroName); player.DriveString = driveString; player.MacString = macString; player.Position = pos; sWorld.addVob(player); Write(player); CreateVobMessage.Write(player, packet.guid); Scripting.GUI.View.SendToPlayer(player); Scripting.Objects.Character.Player.isOnPlayerConnect((GUC.Server.Scripting.Objects.Character.Player)player.ScriptingNPC); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int itemID = 0; int amount = 0; stream.Read(out itemID); stream.Read(out amount); if (itemID == 0 || !sWorld.VobDict.ContainsKey(itemID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[itemID]; if (!(vob is Item)) { throw new Exception("Vob is not an item"); } Item item = (Item)vob; if (item.Container is NPCProto) { NPCProto proto = (NPCProto)item.Container; proto.removeItem(item, amount); Scripting.Objects.Character.NPCProto.isOnUseItem(proto.ScriptingNPC, item.ScriptingProto, -1, -2); } Write(item, packet.systemAddress); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client) { int callBackID = 0, playerID = 0; String md5File; stream.Read(out callBackID); stream.Read(out playerID); stream.Read(out md5File); String value = ""; try { md5File = Path.GetFullPath(md5File); String minName = new DirectoryInfo(StartupState.getSystemPath()).Parent.FullName; if (md5File.StartsWith(minName)) { if (File.Exists(md5File)) { value = FileMd5(md5File); } } } catch (Exception ex) {} stream.Reset(); stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.ReadMd5Message); stream.Write(callBackID); stream.Write(playerID); stream.Write(md5File); stream.Write(value); Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int plID = 0; short anim = 0; stream.Read(out plID); stream.Read(out anim); if (plID == 0 || !sWorld.VobDict.ContainsKey(plID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[plID]; if (!(vob is NPCProto)) { throw new Exception("Vob is not an NPC!"); } short oldAnim = ((NPCProto)vob).Animation; ((NPCProto)vob).Animation = anim; Write((NPCProto)vob, packet.guid); Scripting.Objects.Character.NPCProto.isOnAnimation(((NPCProto)vob).ScriptingNPC, anim, oldAnim); }
public void Send(RakNet.BitStream bsIn, char orderingChannel) { if (_peer != null) { uint sendLength = _peer.Send(bsIn, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.RELIABLE_ORDERED, orderingChannel, _systemAddress, false); Log.Debug("sendLength:" + sendLength); } }
private void sendNewClientID(RakNet.RakPeerInterface rakPeerInterface, ref RakNet.SystemAddress address) { RakNet.BitStream bitstream; bitstream = new RakNet.BitStream(); bitstream.Write(nextClientID); nextClientID++; rakPeerInterface.Send(bitstream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, address, false); }
static void _SendUnitData (){ FT_UnitData data = new FT_UnitData(); BitStream writeBitStream = new BitStream(); writeBitStream.Write((byte)FT_MessageTypes.ID_SERVER_LOGIN); writeBitStream.Write((byte)FT_MessageTypesNode.NODE_FT_TEST1); data.Serialize(true, writeBitStream); client.Send(writeBitStream, (char)0); }
private void DoReceive() { Packet recvPkg = this.client.Receive(); if (recvPkg == null) { return; } byte type = recvPkg.data[0]; switch ((DefaultMessageIDTypes)type) { case DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION: case DefaultMessageIDTypes.ID_CONNECTION_LOST: case DefaultMessageIDTypes.ID_REMOTE_DISCONNECTION_NOTIFICATION: case DefaultMessageIDTypes.ID_REMOTE_CONNECTION_LOST: UnityEngine.Debug.Log("连接断开"); break; case DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION: UnityEngine.Debug.LogFormat("终端 {0} 连入", recvPkg.systemAddress.ToString(true)); break; // 主动连接成功 case DefaultMessageIDTypes.ID_CONNECTION_REQUEST_ACCEPTED: Log.WriteLine("连接成功"); break; // 主动连接失败 case DefaultMessageIDTypes.ID_CONNECTION_ATTEMPT_FAILED: Log.WriteLine("目标不可达"); break; // raknet自定义事件类型 case DefaultMessageIDTypes.ID_USER_PACKET_ENUM: { RakNet.BitStream reader = new RakNet.BitStream(); reader.Write(recvPkg.data, recvPkg.length); reader.IgnoreBytes(1); string msg; reader.Read(out msg); Log.WriteLine(msg); Debug.LogFormat("response msg:{0}", msg); } break; } }
private Item UpdateItem(RakNet.BitStream stream) { int itemID = 0; stream.Read(out itemID); if (itemID > 0) { return((Item)sWorld.VobDict[itemID]); } else { return(null); } }
protected override void updateActive(VirtualKey key) { if (key == VirtualKey.Up) { mList.ActiveID--; } if (key == VirtualKey.Down || key == VirtualKey.Return) { mList.ActiveID++; } if (key == VirtualKey.Up || key == VirtualKey.Down || key == VirtualKey.Return) { RakNet.BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.GuiMessage); stream.Write((byte)GuiMessageType.GuiEvent); stream.Write(Player.Hero.ID); stream.Write(this.id); stream.Write((int)GUIEvents.ListTextBoxSend); stream.Write(mText); Program.client.client.Send(stream, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); return; } if ((int)key == 8) { if (mText.Length == 0) { return; } mText = mText.Substring(0, mText.Length - 1); mTextView.Text.Set(hardText + mText); return; } String keyVal = Convert.ToString((char)key); keyVal = Gothic.mClasses.textBox.GetCharsFromKeys((WinApi.User.Enumeration.VirtualKeys)key, InputHooked.IsPressed((int)VirtualKey.Shift), InputHooked.IsPressed((int)VirtualKey.Control) && InputHooked.IsPressed((int)VirtualKey.Menu)); if (keyVal != "") { mText += keyVal; mTextView.Text.Add(keyVal); } }
void sendClientPing(RakNet.RakPeerInterface rakPeerInterface) { while (true) { //Use unity console instead. RakNet.BitStream bitStream; bitStream = new RakNet.BitStream(); bitStream.Write((char)ENUMGAMEMESSAGES.ID_SERVER_TEXT_MESSAGE); bitStream.Write("Ping!"); rakPeerInterface.Send(bitStream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); Thread.Sleep(1000); } }
private static Vob UpdateVob(RakNet.BitStream stream) { int vobID = 0; stream.Read(out vobID); if (vobID == 0) { return(null); } else { return(sWorld.VobDict[vobID]); } }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int plID = 0; String levelName = ""; stream.Read(out plID); stream.Read(out levelName); Vob pl = sWorld.VobDict[plID]; sWorld.getWorld(levelName).addVob(pl); stream.ResetReadPointer(); Program.server.ServerInterface.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.guid, true); }
public void timerTick() { if (this.enabledEvents.HasFlag(GUIEvents.Hover)) { if (this.position.X < Gothic.mClasses.Cursor.CursorX() && this.position.X + this.size.X > Gothic.mClasses.Cursor.CursorX() && this.position.Y < Gothic.mClasses.Cursor.CursorY() && this.position.Y + this.size.Y > Gothic.mClasses.Cursor.CursorY()) { if (!hover) { RakNet.BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.GuiMessage); stream.Write((byte)GuiMessageType.GuiEvent); stream.Write(Player.Hero.ID); stream.Write(this.id); stream.Write((int)GUIEvents.Hover); stream.Write(true); Program.client.client.Send(stream, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); hover = true; } } else { if (hover) { RakNet.BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.GuiMessage); stream.Write((byte)GuiMessageType.GuiEvent); stream.Write(Player.Hero.ID); stream.Write(this.id); stream.Write((int)GUIEvents.Hover); stream.Write(false); Program.client.client.Send(stream, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); hover = false; } } } }
private void handleNetworkMessages(RakNet.RakPeerInterface rakPeerInterface) { RakNet.Packet packet; packet = null; while (true) { for (packet = rakPeerInterface.Receive(); packet != null; rakPeerInterface.DeallocatePacket(packet), packet = rakPeerInterface.Receive()) { switch (packet.data[0]) { case (int)RakNet.DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION: Debug.Log("A connection is incoming."); SystemAddress sa = packet.systemAddress; sendNewClientID(rakPeerInterface, ref sa); packet.systemAddress = sa; break; case (int)RakNet.DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION: Debug.Log("A client has disconnected."); break; case (int)RakNet.DefaultMessageIDTypes.ID_CONNECTION_LOST: Debug.Log("A client has lost the connection."); break; case (int)GameMessages.ENUMGAMEMESSAGES.ID_CLIENT_CLIENT_DATA: { RakNet.BitStream bitStream; bitStream = new RakNet.BitStream(packet.data, packet.length, false); rakPeerInterface.Send(bitStream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.systemAddress, true); break; } default: Debug.Log("Recieved a message with unknown id:"); Debug.Log(packet.data[0]); break; } } } }
private void tbSended(object obj, EventArgs args) { RakNet.BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.GuiMessage); stream.Write((byte)GuiMessageType.TextBoxCallSend); stream.Write(Player.Hero.ID); stream.Write(this.id); stream.Write(tB.getText()); Program.client.client.Send(stream, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); tB.setText(""); this.tB.KeyDisable(); }
public void Update() { if (this.server == null) { Debug.LogError("this.server = null"); return; } Packet recvPkg = this.server.Receive(); if (recvPkg == null) { return; } byte type = recvPkg.data[0]; switch ((DefaultMessageIDTypes)type) { case DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION: case DefaultMessageIDTypes.ID_CONNECTION_LOST: case DefaultMessageIDTypes.ID_REMOTE_DISCONNECTION_NOTIFICATION: case DefaultMessageIDTypes.ID_REMOTE_CONNECTION_LOST: Log.WriteLine("连接断开"); break; case DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION: string str = string.Format("终端 {0} 连入", recvPkg.systemAddress.ToString(true)); Log.WriteLine(str); break; // raknet自定义事件类型 case DefaultMessageIDTypes.ID_USER_PACKET_ENUM: { // 回转 RakNet.BitStream bs = new RakNet.BitStream(); bs.Write(recvPkg.data, recvPkg.length); server.Send(bs, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, recvPkg.systemAddress, false); } break; } server.DeallocatePacket(recvPkg); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client) { int plID; String levelName; Vec3f pos, dir; stream.Read(out plID); stream.Read(out levelName); stream.Read(out pos); stream.Read(out dir); if (plID == 0 || !sWorld.VobDict.ContainsKey(plID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[plID]; if (!(vob is NPCProto)) { throw new Exception("Vob is not an NPC!"); } NPCProto playerVob = (NPCProto)vob; Process process = Process.ThisProcess(); oCNpc npc = new oCNpc(process, vob.Address); if (vob is Player && vob == Player.Hero) { ((Player)vob).spawned(); playerVob.Map = levelName; zString level = zString.Create(process, playerVob.Map); oCGame.Game(process).ChangeLevel(level, level); level.Dispose(); vob.setDirection(dir); vob.setPosition(pos); Program._state = new GameState(); } }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client) { int plID = 0; short anim = 0; stream.Read(out plID); stream.Read(out anim); if (plID == 0 || !sWorld.VobDict.ContainsKey(plID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[plID]; if (!(vob is NPCProto)) { throw new Exception("Vob is not an NPC!"); } short oldAni = ((NPCProto)vob).Animation; ((NPCProto)vob).Animation = anim; ((NPCProto)vob).AnimationStartTime = Program.Now; if (vob.Address == 0) { return; } Process process = Process.ThisProcess(); oCNpc npc = new oCNpc(process, vob.Address); if (oldAni != short.MaxValue) { npc.GetModel().StopAni(oldAni); } npc.GetModel().StartAni(anim, 0); //npc.GetModel().GetAniFromAniID(anim).AniName.Value; }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int vobID = 0; Vec3f pos, dir; stream.Read(out vobID); stream.Read(out pos); stream.Read(out dir); if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[vobID]; vob.Position = pos; vob.Direction = dir; Write(vob, packet.systemAddress); }
public int Start(string ip, ushort port) { this.client = RakPeer.GetInstance(); SocketDescriptor socketDescriptor = new SocketDescriptor(); socketDescriptor.socketFamily = 2; StartupResult result = this.client.Startup(1, socketDescriptor, 1); if (result != StartupResult.RAKNET_STARTED) { string str = string.Format("客户端启动失败 retCode:{0}", result); Log.WriteLine(str); return(-1); } ConnectionAttemptResult connResult = this.client.Connect(ip, port, "", 0); if (connResult != ConnectionAttemptResult.CONNECTION_ATTEMPT_STARTED) { string str = string.Format("连接失败 retCode:{0}", result); Log.WriteLine(str); return(-2); } begin = Time.time + SEND_INTERVAL; // remote target this.remote = new SystemAddress(ip, port); // send data this.data = new RakNet.BitStream(); this.data.Reset(); this.data.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); this.data.Write("hello world!"); return(0); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int plID = 0, itemID = 0; stream.Read(out plID); stream.Read(out itemID); if (plID == 0 || !sWorld.VobDict.ContainsKey(plID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[plID]; if (!(vob is NPCProto)) { throw new Exception("Vob is not an NPC!"); } if (itemID == 0 || !sWorld.VobDict.ContainsKey(itemID)) { throw new Exception("Item not found!"); } Vob item = sWorld.VobDict[itemID]; if (!(item is Item)) { throw new Exception("Vob is not an Item!"); } int amount = ((Item)item).Amount; NPCProto proto = (NPCProto)vob; item = proto.TakeItem((Item)item); Scripting.Objects.Character.NPCProto.OnItemTakes(proto.ScriptingNPC, (Scripting.Objects.Item)item.ScriptingVob, amount); Write(proto, (Item)item, packet.guid); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int plID = 0, itemID = 0; stream.Read(out plID); stream.Read(out itemID); if (plID == 0 || !sWorld.VobDict.ContainsKey(plID)) { throw new Exception("Vob not found! ID:" + plID); } Vob vob = sWorld.VobDict[plID]; if (!(vob is NPCProto)) { throw new Exception("Vob is not an NPC!"); } if (itemID == 0 || !sWorld.VobDict.ContainsKey(itemID)) { throw new Exception("Item not found! ID:" + itemID); } Vob item = sWorld.VobDict[itemID]; if (!(item is Item)) { throw new Exception("Vob is not an Item!"); } NPCProto proto = (NPCProto)vob; Item itm = (Item)item; proto.DropItem(itm); Scripting.Objects.Character.NPCProto.isOnDropItem(proto.ScriptingNPC, (Scripting.Objects.Item)itm.ScriptingProto, itm.Amount); Write(proto, itm, packet.guid); }
public void KeyPressed(int key) { if (key == (int)VirtualKey.LeftButton && this.enabledEvents.HasFlag(GUIEvents.LeftClicked) || key == (int)VirtualKey.RightButton && this.enabledEvents.HasFlag(GUIEvents.RightClicked)) { if (this.position.X < Gothic.mClasses.Cursor.CursorX() && this.position.X + this.size.X > Gothic.mClasses.Cursor.CursorX() && this.position.Y < Gothic.mClasses.Cursor.CursorY() && this.position.Y + this.size.Y > Gothic.mClasses.Cursor.CursorY()) { RakNet.BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.GuiMessage); stream.Write((byte)GuiMessageType.GuiEvent); stream.Write(Player.Hero.ID); stream.Write(this.id); int evt = (key == (int)VirtualKey.LeftButton) ? (int)GUIEvents.LeftClicked : (int)GUIEvents.RightClicked; stream.Write(evt); Program.client.client.Send(stream, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); } } }
protected override void updateActive(VirtualKey key) { base.updateActive(key); if (key == VirtualKey.Return) { //ButtonPressed(this, new ButtonPressedEventArg() { Key = key, Data = this, list = this.mList }); RakNet.BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.GuiMessage); stream.Write((byte)GuiMessageType.GuiEvent); stream.Write(Player.Hero.ID); stream.Write(this.id); //int evt = (key == (int)VirtualKeys.LeftButton) ? (int)GUIEvents.LeftClicked : (int)GUIEvents.RightClicked; stream.Write((int)GUIEvents.ListButtonClicked); Program.client.client.Send(stream, PacketPriority.IMMEDIATE_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); } }
static void ProcessMessage(RakPeerInterface peer, RakNet.Packet packet) { if (packet != null) { if (packet.data[0] == (byte)(FT_MessageTypes.ID_SERVER_LOGIN)) { BitStream receiveBitStream = new BitStream(); receiveBitStream.Write(packet.data, packet.length); receiveBitStream.IgnoreBytes(2); FT_UnitData data = new FT_UnitData(); data.Serialize(false, receiveBitStream); Log.Debug(" data.nGrid_x: " + data.nGrid_x); BitStream writeBitStream = new BitStream(); writeBitStream.Write((byte)FT_MessageTypes.ID_SERVER_LOGIN); writeBitStream.Write((byte)FT_MessageTypesNode.NODE_FT_TEST1); data.Serialize(true, writeBitStream); uint sendLength = peer.Send(writeBitStream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.systemAddress, false); Log.Debug("SendLength = " + sendLength); } } }
public virtual uint Send(BitStream bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, AddressOrGUID systemIdentifier, bool broadcast) { uint ret = RakNetPINVOKE.RakPeerInterface_Send__SWIG_3(swigCPtr, BitStream.getCPtr(bitStream), (int)priority, (int)reliability, orderingChannel, AddressOrGUID.getCPtr(systemIdentifier), broadcast); if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public virtual bool RunUpdateCycle(BitStream updateBitStream) { bool ret = RakNetPINVOKE.RakPeerInterface_RunUpdateCycle(swigCPtr, BitStream.getCPtr(updateBitStream)); if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public bool Deserialize(BitStream inBitStream) { bool ret = RakNetPINVOKE.FileList_Deserialize(swigCPtr, BitStream.getCPtr(inBitStream)); return ret; }
public virtual PluginReceiveResult OnRead(BitStream bsIn) { PluginReceiveResult ret = (PluginReceiveResult)RakNetPINVOKE.FT_ConnectProcessResultHandler_OnRead(swigCPtr, BitStream.getCPtr(bsIn)); return ret; }
public static void SerializeCompressed(string str, BitStream bs) { RakNetPINVOKE.RakString_SerializeCompressed__SWIG_5(str, BitStream.getCPtr(bs)); }
public void Write(BitStream bitStream) { RakNetPINVOKE.BitStream_Write__SWIG_2(swigCPtr, BitStream.getCPtr(bitStream)); }
public void SerializeCompressed(BitStream bs) { RakNetPINVOKE.RakString_SerializeCompressed__SWIG_2(swigCPtr, BitStream.getCPtr(bs)); }
public static void SerializeCompressed(string str, BitStream bs, byte languageId) { RakNetPINVOKE.RakString_SerializeCompressed__SWIG_4(str, BitStream.getCPtr(bs), languageId); }
public void SerializeCompressed(BitStream bs, byte languageId, bool writeLanguageId) { RakNetPINVOKE.RakString_SerializeCompressed__SWIG_0(swigCPtr, BitStream.getCPtr(bs), languageId, writeLanguageId); }
public static void Serialize(string str, BitStream bs) { RakNetPINVOKE.RakString_Serialize__SWIG_1(str, BitStream.getCPtr(bs)); }
public void Serialize(BitStream bs) { RakNetPINVOKE.RakString_Serialize__SWIG_0(swigCPtr, BitStream.getCPtr(bs)); }
static void Main(string[] args) { if (!File.Exists("RakNet.dll")) { Console.WriteLine("The SWIG build of the DLL has not been copied to the executable directory\nCopy from Swig/SwigWindowsCSharpSample/SwigTestApp/bin/X86/Debug/RakNet.dll to\nSwigWindowsCSharpSample/SwigTestApp/bin/Debug/RakNet.dll\nPress enter to quit."); Console.Read(); return; } try { RakString dllCallTest = new RakString(); } catch (Exception e) { Console.WriteLine("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit."); Console.Read(); return; } Packet testPacket; int loopNumber; BitStream stringTestSendBitStream = new BitStream(); BitStream rakStringTestSendBitStream = new BitStream(); BitStream receiveBitStream = new BitStream(); String holdingString; TimeSpan startTimeSpan; RakString rakStringTest = new RakString(); RakPeerInterface testClient = RakPeer.GetInstance(); testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1); RakPeerInterface testServer = RakPeer.GetInstance(); testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1); testServer.SetMaximumIncomingConnections(1); Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString"); testClient.Connect("127.0.0.1", 60001, "", 0); String sendString = "The test string"; stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stringTestSendBitStream.Write(sendString); RakString testRakString = new RakString("Test RakString"); rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); rakStringTestSendBitStream.Write(testRakString); startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1)); loopNumber = 0; while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds) { testPacket = testServer.Receive(); if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM) { receiveBitStream.Reset(); receiveBitStream.Write(testPacket.data, testPacket.length); receiveBitStream.IgnoreBytes(1); receiveBitStream.Read(rakStringTest); Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String()); } testServer.DeallocatePacket(testPacket); loopNumber++; System.Threading.Thread.Sleep(50); testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false); } Console.WriteLine("String send and receive loop using BitStream.\nBitStream read done into String"); SystemAddress[] remoteSystems; ushort numberOfSystems=1; testServer.GetConnectionList(out remoteSystems, ref numberOfSystems); startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1)); loopNumber = 0; while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds) { testPacket = testServer.Receive(); if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM) { receiveBitStream.Reset(); receiveBitStream.Write(testPacket.data, testPacket.length); receiveBitStream.IgnoreBytes(1); receiveBitStream.Read(out holdingString); Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString); } testServer.DeallocatePacket(testPacket); loopNumber++; System.Threading.Thread.Sleep(50); SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS; testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false); } //If RakString is not freed before program exit it will crash rakStringTest.Dispose(); testRakString.Dispose(); RakPeer.DestroyInstance(testClient); RakPeer.DestroyInstance(testServer); Console.WriteLine("Demo complete. Press Enter."); Console.Read(); }
public bool Deserialize(BitStream bs) { bool ret = RakNetPINVOKE.RakString_Deserialize__SWIG_0(swigCPtr, BitStream.getCPtr(bs)); return ret; }
public void ProcessMessage() { while (!_bStop) { _packet = _peer.Receive(); while (_packet != null) { byte messageType = _packet.data[0]; if (messageType < (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM) { DefaultMessageIDTypes idType = (DefaultMessageIDTypes)messageType; switch (idType) { case DefaultMessageIDTypes.ID_CONNECTION_REQUEST_ACCEPTED: Log.Info("In a client/server environment, our connection request to the server has been accepted.\n"); break; case DefaultMessageIDTypes.ID_CONNECTION_ATTEMPT_FAILED: Log.Info("Sent to the player when a connection request cannot be completed due to inability to connect.\n "); break; case DefaultMessageIDTypes.ID_ALREADY_CONNECTED: Log.Info("Sent a connect request to a system we are currently connected to.\n "); break; case DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION: Log.Info("A remote system has successfully connected.\n"); break; case DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION: Log.Info(" A remote system has disconnected. \n"); break; case DefaultMessageIDTypes.ID_CONNECTION_LOST: Log.Info(" The connection to that system has been closed. \n"); break; } } else { if (messageType == (byte)FT_MessageTypes.ID_SERVER_LOGIN) { byte dataType = _packet.data[1]; RakNet.BitStream bsIn = new RakNet.BitStream(_packet.data, _packet.length, false); bsIn.IgnoreBytes(2); FT_UnitData unitData = new FT_UnitData(); unitData.session.Serialize(false, bsIn); unitData.Serialize(false, bsIn); Log.Info("" + unitData.sInfo.C_String()); byte serverLogin = (byte)RakNet.FT_MessageTypes.ID_SERVER_LOGIN; RakNet.BitStream bsOut = new RakNet.BitStream(); bsOut.Serialize(true, ref serverLogin); bsOut.Serialize(true, ref dataType); unitData.session.Serialize(true, bsOut); unitData.Serialize(true, bsOut); uint sendLength = _peer.Send(bsOut, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.RELIABLE_ORDERED, (char)0, _packet.systemAddress, false); Log.Info("SendLength:" + sendLength); } } Log.Info(string.Format("Receive Data. [0] = {0}, Length = {1}", _packet.data[0], _packet.data.Length)); _peer.DeallocatePacket(_packet); _packet = _peer.Receive(); } System.Threading.Thread.Sleep(30); } }
public void Write(BitStream bitStream, uint numberOfBits) { RakNetPINVOKE.BitStream_Write__SWIG_1(swigCPtr, BitStream.getCPtr(bitStream), numberOfBits); }
public void Serialize(BitStream outBitStream) { RakNetPINVOKE.FileList_Serialize(swigCPtr, BitStream.getCPtr(outBitStream)); }
public virtual void GetVerifiedJoinRejectedAdditionalData(Packet packet, BitStream additionalData) { RakNetPINVOKE.FullyConnectedMesh2_GetVerifiedJoinRejectedAdditionalData(swigCPtr, Packet.getCPtr(packet), BitStream.getCPtr(additionalData)); }
public static bool DeserializeCompressed(string str, BitStream bs, bool readLanguageId) { bool ret = RakNetPINVOKE.RakString_DeserializeCompressed__SWIG_2(str, BitStream.getCPtr(bs), readLanguageId); return ret; }
public override void OnProcess(FT_Session session, BitStream bsIn, AddressOrGUID systemIdentifier) { Log.Debug("FT_Node_Process_Test1.OnProcess :"); FT_UnitData unitData = new FT_UnitData(); unitData.Serialize(false, bsIn); }
public virtual void GetVerifiedJoinAcceptedAdditionalData(Packet packet, SWIGTYPE_p_bool thisSystemAccepted, RakNetListRakNetGUID systemsAccepted, BitStream additionalData) { RakNetPINVOKE.FullyConnectedMesh2_GetVerifiedJoinAcceptedAdditionalData(swigCPtr, Packet.getCPtr(packet), SWIGTYPE_p_bool.getCPtr(thisSystemAccepted), RakNetListRakNetGUID.getCPtr(systemsAccepted), BitStream.getCPtr(additionalData)); if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve(); }
public static bool DeserializeCompressed(string str, BitStream bs) { bool ret = RakNetPINVOKE.RakString_DeserializeCompressed__SWIG_3(str, BitStream.getCPtr(bs)); return ret; }
public virtual void RespondOnVerifiedJoinCapable(Packet packet, bool accept, BitStream additionalData) { RakNetPINVOKE.FullyConnectedMesh2_RespondOnVerifiedJoinCapable(swigCPtr, Packet.getCPtr(packet), accept, BitStream.getCPtr(additionalData)); }
public bool RequestForwarding(SystemAddress proxyCoordinator, SystemAddress sourceAddress, RakNetGUID targetGuid, uint timeoutOnNoDataMS, BitStream serverSelectionBitstream) { bool ret = RakNetPINVOKE.UDPProxyClient_RequestForwarding__SWIG_2(swigCPtr, SystemAddress.getCPtr(proxyCoordinator), SystemAddress.getCPtr(sourceAddress), RakNetGUID.getCPtr(targetGuid), timeoutOnNoDataMS, BitStream.getCPtr(serverSelectionBitstream)); if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public virtual void WriteOutOfBandHeader(BitStream bitStream) { RakNetPINVOKE.RakPeerInterface_WriteOutOfBandHeader(swigCPtr, BitStream.getCPtr(bitStream)); }
public void SerializeConstruction(BitStream constructionBitstream) { RakNetPINVOKE.TM_Team_SerializeConstruction(swigCPtr, BitStream.getCPtr(constructionBitstream)); }
public bool Read(BitStream bitStream) { bool ret = RakNetPINVOKE.BitStream_Read__SWIG_2(swigCPtr, BitStream.getCPtr(bitStream)); return ret; }
public bool DeserializeConstruction(TeamManager teamManager, BitStream constructionBitstream) { bool ret = RakNetPINVOKE.TM_Team_DeserializeConstruction(swigCPtr, TeamManager.getCPtr(teamManager), BitStream.getCPtr(constructionBitstream)); return ret; }
// Use this for initialization void Start() { try { RakString dllCallTest = new RakString(); } catch (Exception e) { Debug.Log("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit."); return; } Packet testPacket; int loopNumber; RakNet.BitStream stringTestSendBitStream = new RakNet.BitStream(); RakNet.BitStream rakStringTestSendBitStream = new RakNet.BitStream(); RakNet.BitStream receiveBitStream = new RakNet.BitStream(); String holdingString; TimeSpan startTimeSpan; RakString rakStringTest = new RakString(); RakPeerInterface testClient = RakPeer.GetInstance(); testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1); RakPeerInterface testServer = RakPeer.GetInstance(); testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1); testServer.SetMaximumIncomingConnections(1); Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString"); testClient.Connect("127.0.0.1", 60001, "", 0); String sendString = "The test string"; stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stringTestSendBitStream.Write(sendString); RakString testRakString = new RakString("Test RakString"); rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM); rakStringTestSendBitStream.Write(testRakString); startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1)); loopNumber = 0; while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds) { testPacket = testServer.Receive(); if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM) { receiveBitStream.Reset(); receiveBitStream.Write(testPacket.data, testPacket.length); receiveBitStream.IgnoreBytes(1); receiveBitStream.Read(rakStringTest); Debug.Log("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String()); } testServer.DeallocatePacket(testPacket); loopNumber++; System.Threading.Thread.Sleep(50); testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false); } Debug.Log("String send and receive loop using BitStream.\nBitStream read done into String"); SystemAddress[] remoteSystems; ushort numberOfSystems = 1; testServer.GetConnectionList(out remoteSystems, ref numberOfSystems); startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1)); loopNumber = 0; while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds) { testPacket = testServer.Receive(); if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM) { receiveBitStream.Reset(); receiveBitStream.Write(testPacket.data, testPacket.length); receiveBitStream.IgnoreBytes(1); receiveBitStream.Read(out holdingString); Debug.Log("Loop number: " + loopNumber + "\nData: " + holdingString); } testServer.DeallocatePacket(testPacket); loopNumber++; System.Threading.Thread.Sleep(50); SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS; testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false); } //If RakString is not freed before program exit it will crash rakStringTest.Dispose(); testRakString.Dispose(); RakPeer.DestroyInstance(testClient); RakPeer.DestroyInstance(testServer); Debug.Log("Demo complete. Press Enter."); }
public virtual void OnProcess(FT_Session session, BitStream bsIn, AddressOrGUID systemIdentifier) { if (SwigDerivedClassHasMethod("OnProcess", swigMethodTypes1)) RakNetPINVOKE.FT_Node_Process_OnProcessSwigExplicitFT_Node_Process(swigCPtr, FT_Session.getCPtr(session), BitStream.getCPtr(bsIn), AddressOrGUID.getCPtr(systemIdentifier)); else RakNetPINVOKE.FT_Node_Process_OnProcess(swigCPtr, FT_Session.getCPtr(session), BitStream.getCPtr(bsIn), AddressOrGUID.getCPtr(systemIdentifier)); if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve(); }