private long SendingProcess(FileStream file, FileModel fileModel, long packetNumber) { var data = new byte[4096]; using (var stream = new PacketWriter()) { stream.Write(packetNumber); long fileposition = file.Position; stream.Write(fileposition); data.InsertInStartArray(stream.ToByteArray()); } var packet = new PacketModel() { Number = packetNumber, IsSend = true, Size = data.Length - 2 * sizeof(long), FilePosition = file.Position }; packetNumber++; file.Read(data, 2 * sizeof(long), data.Length - 2 * sizeof(long)); socket.Send(data); fileModel.Packets.Add(packet); Console.Write("\rSending... " + (fileModel.Packets.Where(x => x.IsSend).Sum(x => x.Size) * 100 / fileModel.Size) + "%"); return(packetNumber); }
public string MakePacket(string eventName, string data) { PacketModel packet = new PacketModel { EventName = eventName, JsonPayLoad = data }; return(JsonConvert.SerializeObject(packet)); }
public void SendCommand(string command) { PacketModel packet = new PacketModel() { Identifier = 1, Message = command, Name = "RustManager" }; string packetString = JsonConvert.SerializeObject(packet); _webSocket.SendAsync(packetString, null); }
private void ResendingData(FileStream file, FileModel fileModel, PacketModel packet) { var data = new byte[4096]; using (var stream = new PacketWriter()) { stream.Write(packet.Number); stream.Write(packet.FilePosition); data.InsertInStartArray(stream.ToByteArray()); } DataSending(file, fileModel, packet, data); Console.Write("\rResending UDP... " + (fileModel.Packets.Sum(x => x.Size) * 100 / fileModel.Size)); }
internal PacketModel[] GetRandomly(int packetCount, params uint[] opcodes) { var opcodeList = opcodes.ToList(); var ret = new PacketModel[opcodeList.Count]; for (var i = 0; i < packetCount; i++) { var pack = GetNextPacket(); var index = opcodeList.IndexOf(pack.Opcode); if (index != -1) { ret[index] = pack; } } return(ret); }
private void OnMessage(object sender, MessageEventArgs e) { PacketModel packet = PacketModel.ReadData(e.Data); if (string.IsNullOrEmpty(packet.Message)) { return; } if (packet.Type == "Chat") { ChatPacketModel chat = packet as ChatPacketModel; _outputFunction($"[CHAT] | {chat.Username} [{chat.UserID}]: {chat.ChatMessage}"); return; } if (packet.Type == "Generic") { _outputFunction(packet.Message); return; } _outputFunction($"Error! Uncaught packet type: {packet.Type}"); }
// POST: api/RoutePlan public IEnumerable <RouteAPIModel> Post(PacketModel packetModel) { List <Route> routes = new List <Route>(); // routePlanService.findShortestRoute(dummyPackage); TODO var route1 = new Route() { DestinationA = new Airport() { Availability = true, Name = "Cairo" }, DestinationB = new Airport() { Availability = true, Name = "Zanzibar" }, Time = new DateTime().AddHours(8), PacketPrice = new PacketPrice() { Weight = new Weight() { Max = 1, Min = 0.1f }, Price = new Price() { Currency = "USD", Amount = 40 } }, RouteID = 1 }; var route2 = new Route() { DestinationA = new Airport() { Availability = true, Name = "Congo" }, DestinationB = new Airport() { Availability = true, Name = "Zanzibar" }, Time = new DateTime().AddHours(8), PacketPrice = new PacketPrice() { Weight = new Weight() { Max = 1, Min = 0.1f }, Price = new Price() { Currency = "USD", Amount = 40 } }, RouteID = 1 }; routes.Add(route1); routes.Add(route2); var routeOutputModels = routes.Select(route => new RouteAPIModel() { From = route.DestinationA.Name, To = route.DestinationB.Name, Price = route.PacketPrice.Price, Time = route.Time.ToString("dd:HH:mm:ss") } ); return(routeOutputModels); }
internal bool Auth(string user, string pass, out string reason) { try { if (!AuthClientHandler.Instance.CheckConnection()) { throw new Exception(); } AuthClientHandler.Instance.Write(_ping); var packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _pong) { reason = "Recieved wrong packets"; return(false); } var accName = new PacketModel { Opcode = _accountName, Content = Encoding.Unicode.GetBytes(user.ToLower()) }; var accPass = new PacketModel { Opcode = _accountPassword, Content = Encoding.Unicode.GetBytes(pass) }; AuthClientHandler.Instance.WriteRandomly(10, accName, accPass); packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _loginResult) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "The account data seems to be invalid (false password, no credits etc.)"; Console.WriteLine(reason); return(false); } packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _newSessionResult) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "Max sessions reached"; Console.WriteLine(reason); return(false); } //AuthClientHandler.Instance.Write(_hardwareId); //packet = AuthClientHandler.Instance.GetNextPacket(); //if (packet.Opcode != _hardwareIdResult) //{ // reason = "Recieved wrong packets"; // return false; //} //if (packet.Content[0] != 1) //{ // reason = "All sessions for this account must be run on the same PC"; // Console.WriteLine(reason); // return false; //} AuthClientHandler.Instance.Write(_md5String, "TEST".ToByte()); packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _md5StringResult) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "Please update the software"; Console.WriteLine(reason); return(false); } AuthClientHandler.Instance.Write(_botVersion, new byte[] { 1 }); packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _botVersionReuslt) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "Your product isnt supported by this authentication server"; Console.WriteLine(reason); return(false); } var packets = AuthClientHandler.Instance.GetRandomly(10, _wardenLoadDetour, _wardenMemCpyDetour); var loadDetour = packets[0].Content.BToString(); var memcpyDetour = packets[1].Content.BToString(); InitHeartbeat(); reason = ""; return(true); } catch { } reason = "Something went wrong. Authentication server might be unreachable."; return(false); }
public PacketModel OpenPacket(string data) { PacketModel packet = JsonConvert.DeserializeObject <PacketModel>(data); return(packet); }
internal bool Auth(string user, string pass, out string reason) { try { if (!AuthClientHandler.Instance.CheckConnection()) { throw new Exception(); } AuthClientHandler.Instance.Write(_ping); var packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _pong) { reason = "Recieved wrong packets"; return(false); } var accName = new PacketModel { Opcode = _accountName, Content = Encoding.Unicode.GetBytes(user.ToLower()) }; var accPass = new PacketModel { Opcode = _accountPassword, Content = Encoding.Unicode.GetBytes(pass) }; AuthClientHandler.Instance.WriteRandomly(10, accName, accPass); packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _loginResult) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "The account data seems to be invalid (false password, no credits etc.)"; Console.WriteLine(reason); return(false); } packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _newSessionResult) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "Max sessions reached"; Console.WriteLine(reason); return(false); } //AuthClientHandler.Instance.Write(_hardwareId); //packet = AuthClientHandler.Instance.GetNextPacket(); //if (packet.Opcode != _hardwareIdResult) //{ // reason = "Recieved wrong packets"; // return false; //} //if (packet.Content[0] != 1) //{ // reason = "All sessions for this account must be run on the same PC"; // Console.WriteLine(reason); // return false; //} #if DEBUG AuthClientHandler.Instance.Write(_md5String, "OpenSource".ToByte()); #else AuthClientHandler.Instance.Write(_md5String, App.GetMd5AsBase64(Assembly.GetExecutingAssembly().Location).ToByte()); #endif packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _md5StringResult) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "Please update the software"; Console.WriteLine(reason); return(false); } AuthClientHandler.Instance.Write(_botVersion, new byte[] { 3 }); packet = AuthClientHandler.Instance.GetNextPacket(); if (packet.Opcode != _botVersionReuslt) { reason = "Recieved wrong packets"; return(false); } if (packet.Content[0] != 1) { reason = "Your product isnt supported by this authentication server"; Console.WriteLine(reason); return(false); } var packets = AuthClientHandler.Instance.GetRandomly(10, _wardenLoadDetour, _wardenMemCpyDetour, _WardenPageScanDetour, _eventSignal0Detour, _eventSignalDetour); var loadDetour = packets[0].Content.BToString(); var memcpyDetour = packets[1].Content.BToString(); var pageScanDetour = packets[2].Content.BToString(); var eventSignal0 = packets[3].Content.BToString(); var eventSignal = packets[4].Content.BToString(); SendOvers.WardenLoadDetour = loadDetour.Split(new string[] { "[|]" }, StringSplitOptions.RemoveEmptyEntries); SendOvers.WardenMemCpyDetour = memcpyDetour.Split(new string[] { "[|]" }, StringSplitOptions.RemoveEmptyEntries); SendOvers.WardenPageScanDetour = pageScanDetour.Split(new string[] { "[|]" }, StringSplitOptions.RemoveEmptyEntries); SendOvers.EventSignal0 = eventSignal0.Split(new string[] { "[|]" }, StringSplitOptions.RemoveEmptyEntries); SendOvers.EventSignal = eventSignal.Split(new string[] { "[|]" }, StringSplitOptions.RemoveEmptyEntries); InitHeartbeat(); reason = ""; return(true); } catch { } reason = "Something went wrong. Authentication server might be unreachable."; return(false); }