public unsafe static int SetPacketVersion(this Socket socket, PacketVersions version) { var v = (int)version; var result = setsockopt((int)socket.Handle, SocketOptionLevels.SOL_PACKET, SocketOptions.PACKET_VERSION, &v, sizeof(int)); return(ValidateResult(result)); }
/// <summary> /// Called when the server receives a packet that it cannot handle. /// </summary> /// <param name="pSocket">The servers socket which received the packet.</param> unsafe static bool OnHandleOutsideRangePacket(byte *pSocket) { //ClientSocket sock = new ClientSocket(pSocket); byte PacketID = *(pSocket + 0x28); uint PacketSize = 0; bool IsPacketDynamicSized = false; ClientVersionStruct ver = *(ClientVersionStruct *)(pSocket + 0x1003C); ClientVersion version; if (PacketID == 0xBB && ver < ClientVersion.v1_26_0) // detect client 1.26.0 { UODemo.ISocket socket = UODemo.Socket.Acquire(Server.Core, (struct_ServerSocket *)pSocket); //ClientSocket(pSocket); version = ClientVersion.v1_26_0; socket.SetClientVersion(version.Version); } else { version = ClientVersion.Instantiate(ver); } PacketVersionEntry packetinfo = PacketVersions.GetPacketInfo(PacketID, version); if (packetinfo == null) { ConsoleUtils.PushColor(ConsoleColor.Red); Console.WriteLine("WARNING: Ignored Invalid Packet {0:X2}.", PacketID); ConsoleUtils.PopColor(); return(false); } else { //case 0xB6: PacketSize = 9; IsPacketDynamicSized = false; break; //case 0xB8: PacketSize = 0; IsPacketDynamicSized = true; break; //case 0xBB: PacketSize = 9; IsPacketDynamicSized = false; break; //case 0xBD: PacketSize = 0; IsPacketDynamicSized = true; break; //default: PacketSize = packetinfo.Length; IsPacketDynamicSized = packetinfo.Dynamic; if (MyServerConfig.PacketDebug) { Console.WriteLine("Handling Invalid Packet {0:X2} from client version {1}", PacketID, version); } OnPacketReceived(pSocket, PacketID, PacketSize, IsPacketDynamicSized ? -1 : 0); return(true); } }
/// <summary> /// Called once, on first pulse from server. Set everything up here. /// </summary> public static void Initialize() { if (!Initialized) { // Call all class configuration routines. WorldSave.Configure(); Accounting.Configure(); PacketVersions.Configure(); Initialized = true; Sharpkick.WorldBuilding.Builder.Configure(); Console.WriteLine("Sharpkick Initialized."); } }
static void Main(string[] args) { WebSocket websocket = new WebSocket("ws://127.0.0.1:8080"); int packetSeq = 0; Protocol0Header rxheader; Protocol0Body rxbody; Guid ourUUID = Guid.Empty; Guid crassusUUID = Guid.Empty; Random random = new Random(); // Shortcut functions Protocol0 fastPacket = new Protocol0(); websocket.OnMessage += (sender, data) => { // Parse the inbound packet JArray dataBlockMaster = JArray.Parse(data.Data); // Convert into tokens IList <JToken> dataBlockChildren = dataBlockMaster.Children().ToList(); // PacketSeq packetSeq++; //Console.WriteLine("Json RX: {0}", data.Data); if (packetSeq == 1) { foreach (JToken clientPluginVersion in dataBlockChildren) { protocolVersion.Add(clientPluginVersion.ToObject <uint>()); Console.WriteLine("Server supports: {0}", clientPluginVersion); } if (protocolVersion.Count == 0) { Console.WriteLine("We do not support any mutual version the server does!"); websocket.Close(); } else { Console.WriteLine("Using protocol: {0}", protocolVersion[0]); } } else if (packetSeq == 2) { rxheader = dataBlockChildren[0].ToObject <Protocol0Header>(); rxbody = dataBlockChildren[1].ToObject <Protocol0Body>(); Guid[] decodedJson = JsonConvert.DeserializeObject <Guid[]>(rxbody.data); crassusUUID = decodedJson[0]; ourUUID = decodedJson[1]; Console.WriteLine( "Our UUID is: {0},\nThe crassus controller is on: {1}", ourUUID, crassusUUID ); // Lets send a subscribe! string channelQuery = fastPacket.CrassusCommand( crassusUUID, ourUUID, new string[] { "SUBSCRIPTION", "LIST" } ); websocket.Send(channelQuery); } else if (packetSeq == 3) { rxheader = dataBlockChildren[0].ToObject <Protocol0Header>(); rxbody = dataBlockChildren[1].ToObject <Protocol0Body>(); string[] channels = JsonConvert.DeserializeObject <string[]>(rxbody.data); foreach (string channel in channels) { Console.WriteLine("Server has a channel: {0}", channel); if (!channel.Equals("ECHO")) { continue; } websocket.Send( fastPacket.CrassusCommand( crassusUUID, ourUUID, new string[] { "SUBSCRIPTION", "ADD", channel } ) ); } } else { rxheader = dataBlockChildren[0].ToObject <Protocol0Header>(); rxbody = dataBlockChildren[1].ToObject <Protocol0Body>(); } // Elsewhere this is a normal packet! }; websocket.OnOpen += (sender, data) => { }; websocket.OnClose += (sender, data) => { }; websocket.Connect(); { websocket.Send(JsonConvert.SerializeObject(PacketVersions.ToArray())); } Console.ReadKey(); }