Compare commits

..

No commits in common. "8e8bf0d53cef571a37da8d964ebf5dee01732f37" and "625579e51098e574534226a68dc8bcab97a61085" have entirely different histories.

7 changed files with 56 additions and 213 deletions

View File

@ -1,6 +1,4 @@
// //
import 'dart:convert';
List skey = [8, 1, 2, 5, 4]; List skey = [8, 1, 2, 5, 4];
// //
@ -13,8 +11,8 @@ String makecodeChar(String c, int key, int key2) {
// //
String cutcodeChar(String c, int key, int key2) { String cutcodeChar(String c, int key, int key2) {
int charCode = c.codeUnitAt(0); int charCode = c.codeUnitAt(0);
int decryptedCharCode = (((charCode - 1) ^ key) ^ key2) - key; charCode = (((charCode - 1) ^ key) ^ key2) - key;
return String.fromCharCode(decryptedCharCode); return String.fromCharCode(charCode);
} }
// //
@ -27,11 +25,8 @@ String makecode(String pstr, List pkey) {
} }
// //
String cutecode(List<int> pstr) { void cutecode(String pstr, List pkey) {
int len = pstr.length; for (int i = 0; i < pstr.length; i++) {
for (int i = 0; i < len; i++) { pstr = pstr.replaceRange(i, i + 1, cutcodeChar(pstr[i], pkey[i % 5], pkey[(i + 18) % 5]));
pstr[i] = cutcodeChar(String.fromCharCode(pstr[i])
, skey[i % 5], skey[(i + 18) % 5]).codeUnitAt(0);
} }
return String.fromCharCodes(pstr);
} }

View File

@ -7,42 +7,18 @@ class NumberTool {
/// @allNum: /// @allNum:
/// @num: /// @num:
List<int> randomNum(int allNum, {int num = 10}) { List<int> randomNum(int allNum, {int num = 10}) {
Random random = Random(); List<int> randomNumbers = [];
int remainingNum = allNum;
//
int base = allNum ~/ 1.5 ~/ num;
List<int> numbers = List.generate(num, (index) => base);
for (int i = 0; i < num - 1; i++) { for (int i = 0; i < num - 1; i++) {
int randomNumber = random.nextInt(base); // 0base之间的随机整数 int randomNumber = Random().nextInt(remainingNum) + 1;
numbers[i] += randomNumber; randomNumbers.add(randomNumber);
remainingNum -= randomNumber;
} }
int sum = numbers.reduce((a, b) => a + b) ; randomNumbers.add(allNum - randomNumbers.fold(0, (prev, element) => prev + element));
int lastNumber = allNum - sum;
// /2 / return randomNumbers;
base = (lastNumber / 2) ~/ (num);
for (int i = 0; i < num - 1; i++) {
numbers[i] += base;
}
sum = numbers.reduce((a, b) => a + b);
lastNumber = allNum - sum;
//
base = lastNumber ~/ 2;
numbers[ random.nextInt(num - 1)] = base;
sum = numbers.reduce((a, b) => a + b);
lastNumber = allNum - sum;
numbers.add(lastNumber);
//
numbers.shuffle();
return numbers;
} }
} }

View File

@ -2,11 +2,8 @@ import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:web_synchronization_tool/windows/synchronization_web_tool.dart';
import 'little_extension.dart'; import 'little_extension.dart';
import 'code.dart'; import 'code.dart';
import 'number_tool.dart';
class SocketUtils extends Socket{ class SocketUtils extends Socket{
// //
@ -24,114 +21,39 @@ class SocketUtils extends Socket{
class Socket { class Socket {
String url = '127.0.0.1'; static String url = '127.0.0.1';
static int port = 12345; static int port = 12345;
RawDatagramSocket? socket; RawDatagramSocket? socket;
// IC 0 1
int ic = 1;
/// ip
List<String> childrenIp = [];
connect() async { connect() async {
socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0); socket = await RawDatagramSocket.bind('127.0.0.2', 1);
print('UDP Socket bound to ${socket?.address.address}:${socket?.port}');
//
Map data = {
"op": 0,
"IC": ic
};
socket?.send(dataMake(data), InternetAddress(url), port);
// //
socket?.listen((RawSocketEvent e) { socket?.listen((RawSocketEvent e) {
Datagram? d = socket?.receive(); Datagram? d = socket?.receive();
if (d == null) return; if (d == null) return;
Map data = dataCute(d.data); // String message = String.fromCharCodes(d.data).trim();
// print('Datagram from ${d.address.address}:${d.port}: $message');
//
if (data['op'] == 2){
print(data);
//
if (data['click'] != null){
Map click = data['click'];
int x = click['x'] as int;
int y = click['y'] as int;
SynchronizationWebTool.getInstance().clickSynchronization(x, y);
}
//
if (data['input'] != null){
int input = data['input'];
List<int> nums = NumberTool().randomNum(input);
SynchronizationWebTool.getInstance().input(nums);
}
}
//
if (data['op'] == 11){
}
// ip
if (data['Arr'] != null){
List arr = data['Arr'];
List<String> ips = [];
arr.forEach((clientMap) {
String ip = clientMap['Client'];
ips.add(ip);
});
childrenIp = ips;
}
}); });
heartbeat();
} }
/// ///
sendClickMessage(Map data){ sendMessage(Map data){
Map messageMap = { socket?.send(dataMake(data), InternetAddress(url), port);
"op": 2,
"click": data
};
socket?.send(dataMake(messageMap), InternetAddress(url), port);
} }
///
sendGetChilds(){
Map messageMap = {
"op": 3,
};
socket?.send(dataMake(messageMap), InternetAddress(url), port);
}
///
sendInpuMessage(int num){
Map messageMap = {
"op": 2,
"input": num
};
socket?.send(dataMake(messageMap), InternetAddress(url), port);
}
/// ///
heartbeat(){ heartbeat(){
Timer timer = Timer(const Duration(seconds: 10), () async { Timer timer = Timer(const Duration(seconds: 10), () {
if (socket == null){
//
await connect();
}
Map data = { Map data = {
"op": 1, "op": 1,
"IC": ic "IC": 0
}; };
socket?.send(dataMake(data), InternetAddress(url), port); socket?.send(dataMake(data), InternetAddress(url), port);
@ -152,18 +74,4 @@ class Socket {
return uinData.toList(); return uinData.toList();
} }
///
Map dataCute(Uint8List data){
if (data.length <= 4) return {};
Uint8List pData = data.sublist(4,data.length);
String str = cutecode(pData);
Map map = json.decode(str);
return map;
}
} }

View File

@ -50,11 +50,11 @@ class SynchronizationWebTool{
if (event['click'] != null) { if (event['click'] != null) {
Map click = event['click']; Map click = event['click'];
int x = click['x'] as int; double x = (click['x'] as int).toDouble();
int y = click['y'] as int; double y = (click['y'] as int).toDouble();
clickSynchronization(x, y); clickSynchronization(x, y);
SocketUtils.getInstance().sendClickMessage(click); SocketUtils.getInstance().sendMessage(event);
} }
if (event['scroll'] != null ) { if (event['scroll'] != null ) {
@ -72,7 +72,7 @@ class SynchronizationWebTool{
} }
/// ///
clickSynchronization(int x,int y){ clickSynchronization(double x,double y){
for (var controller in childController) { for (var controller in childController) {
controller.executeScript(WindowsJs.clickJs(x, y)); controller.executeScript(WindowsJs.clickJs(x, y));
} }

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:web_synchronization_tool/windows/number_tool.dart'; import 'package:web_synchronization_tool/windows/number_tool.dart';
import 'package:web_synchronization_tool/windows/socket_tool.dart';
import 'package:web_synchronization_tool/windows/synchronization_web_tool.dart'; import 'package:web_synchronization_tool/windows/synchronization_web_tool.dart';
import 'package:web_synchronization_tool/windows/windowsJs.dart'; import 'package:web_synchronization_tool/windows/windowsJs.dart';
import 'package:webview_windows/webview_windows.dart'; import 'package:webview_windows/webview_windows.dart';
@ -116,12 +115,8 @@ class ShowWebWidget extends StatefulWidget {
class _ShowWebWidgetState extends State<ShowWebWidget> { class _ShowWebWidgetState extends State<ShowWebWidget> {
/// TextEditingController textController = TextEditingController();
TextEditingController urlController = TextEditingController();
///
TextEditingController numController = TextEditingController(); TextEditingController numController = TextEditingController();
/// ip
TextEditingController ipController = TextEditingController();
@override @override
void dispose() { void dispose() {
@ -157,79 +152,19 @@ class _ShowWebWidgetState extends State<ShowWebWidget> {
widget.controller.openDevTools(); widget.controller.openDevTools();
}, },
child: const Text('开发者')), child: const Text('开发者')),
inputNumber(),
Row( Row(
children: [
const Text('同步'),
Switch(
value: SynchronizationWebTool.getInstance().webSync,
onChanged: (value) {
setState(() {
SynchronizationWebTool.getInstance().webSync = value;
if (value){ //
SocketUtils.getInstance().sendGetChilds();
}
});
})
],
),
input(),
ipSet()
],
);
}
///
input(){
return Row(
children: [
SizedBox(width: 400, child: TextField(style: const TextStyle(fontSize: 14),controller: urlController,)),
TextButton(onPressed: (){
String url = urlController.text;
// if (!url.startsWith("https://") ) {
// url = "https://$url";
// }
widget.controller.loadUrl(url);
}, child: const Text('跳转',style: TextStyle(fontSize: 14),))
],
);
}
ipSet(){
ipController.text = SocketUtils.getInstance().url;
return Row(
children: [
SizedBox(width: 100, child: TextField(style: const TextStyle(fontSize: 14),controller: ipController,)),
TextButton(onPressed: (){
SocketUtils.getInstance().url = ipController.text;
SocketUtils.getInstance().connect();
}, child: const Text('保存服务器ip',style: TextStyle(fontSize: 14),))
],
);
}
///
inputNumber(){
return Row(
children: [ children: [
SizedBox(width: 100, child: TextField(style: const TextStyle(fontSize: 14),controller: numController,)), SizedBox(width: 100, child: TextField(style: const TextStyle(fontSize: 14),controller: numController,)),
TextButton( TextButton(
onPressed: () { onPressed: () {
try{ try{
int num = int.parse(numController.text); int num = int.parse(numController.text);
if (num <= 10){
int chidNum = SocketUtils.getInstance().childrenIp.length + 1; numController.text = '金额不能小于10';
if (num <= chidNum * 10){
numController.text = '金额不能小于${chidNum*10}';
return; return;
} }
int maxNum = num ~/ chidNum; List<int> nums = NumberTool().randomNum(num,num: SynchronizationWebTool.getInstance().childController.length);
SocketUtils.getInstance().sendInpuMessage(maxNum);
//
List<int> nums = NumberTool().randomNum(maxNum);
widget.controller.executeScript(WindowsJs.inputJs(nums.first)); widget.controller.executeScript(WindowsJs.inputJs(nums.first));
nums.removeAt(0); nums.removeAt(0);
SynchronizationWebTool.getInstance().input(nums); SynchronizationWebTool.getInstance().input(nums);
@ -239,6 +174,36 @@ class _ShowWebWidgetState extends State<ShowWebWidget> {
}, },
child: const Text('填入总金额')), child: const Text('填入总金额')),
], ],
),
Row(
children: [
const Text('同步'),
Switch(
value: SynchronizationWebTool.getInstance().webSync,
onChanged: (value) {
setState(() {
SynchronizationWebTool.getInstance().webSync = value;
});
})
],
),
input()
],
);
}
input(){
return Row(
children: [
SizedBox(width: 400, child: TextField(style: const TextStyle(fontSize: 14),controller: textController,)),
TextButton(onPressed: (){
String url = textController.text;
// if (!url.startsWith("https://") ) {
// url = "https://$url";
// }
widget.controller.loadUrl(url);
}, child: const Text('跳转',style: TextStyle(fontSize: 14),))
],
); );
} }

View File

@ -75,7 +75,7 @@ document.addEventListener("click", function (event) {
} }
/// ///
static String clickJs(int x, int y) { static String clickJs(double x, double y) {
return 'document.elementFromPoint($x, $y).click();'; return 'document.elementFromPoint($x, $y).click();';
} }

View File

@ -24,9 +24,6 @@ class _WindowsPageState extends State<WindowsPage> {
void initState() { void initState() {
super.initState(); super.initState();
SocketUtils.getInstance().connect();
SocketUtils.getInstance().heartbeat();
controllerInit(); controllerInit();
} }
@ -45,6 +42,8 @@ class _WindowsPageState extends State<WindowsPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
SocketUtils.getInstance().connect();
if (initDone == false) return Container(); if (initDone == false) return Container();
return Scaffold( return Scaffold(