跳到正文

个人记录

整合计划倒闭啦哈哈哈哈哈哈哈,是啊哈指使我这么做的哈哈哈哈哈

keatsli约 41 分钟
原文

这是 2026年2月4日 存档的第 25 版,不是当前版本。查看当前版本

文章信息与版本

整合计划倒闭啦哈哈哈哈哈哈哈,是啊哈指使我这么做的哈哈哈哈哈

亲爱的 Luogu 社区朋友们,

我们正面临一个绝佳的机会——通过集中普通用户的 accesskey,使普通用户的图像维护更加简单!

在此,我诚挚地向大家提出一个合作计划:将您的 accesskey 委托给我管理,我为您提供维护图像的服务,具体地,我将用所有征集到的 accesskey 共同维护所有图像。

什么是冬日绘板 accesskey

在 LGS Paintboard 中,Token 是进行绘画操作的唯一凭证。每一个 Token 都与您的 accesskey 绑定,用于在画板上放置像素点。

没有 accesskey 就无法在画板上进行任何绘画操作,accesskey 是参与集体绘画的”钥匙”。

而我获得 Token 的方式即为使用您的 accesskey 生成,因此您需要提供您的 accesskey。

为什么需要您的 accesskey?

规模效应

accesskey 数量与可维护的像素面积之间的关系大约是一个 下凸单增函数。这意味着:

  • 当 Token集中使用时 ,整体效率将大幅提升
  • 我们能够维护的图像面积将远超各自为战的分散模式
  • 每增加一个 accesskey ,带来的边际效益实际上在增加
  • 你只需要自己和一部分亲朋好友的 accesskey 即可在绘板上稳定维护自己的图像!

技术优势

我的脚本在不限制绘画间隔时可以覆盖全图绝大部分位置(Furina 大人万岁!)。

承诺与诚信

我们仅维护您提供的图像(图片像素数与您提供的 accesskey 数成正比),除了一个 4×4 像素的参战标志(如下)外,绝不添加任何个人内容(可能会在测试阶段维护宣传图像喵,毕竟,Accesskey 越多越好喵!)。

参战标志喵

完全透明,共同监督

所有贡献者的 UID 将在此公示:


377782 676520 1208635 1366666 695525 1063830 947762 913226 718740 822013 1794272 757883 928604 541523 1740638 729231 1208985 824868 1757577 1113349 1102836 926578 1846549 812227 1235819 950498 998906 1315112 557261 964822 1801879 1357229 1124941 8267 1140668 1208758 1841469 1209652 130921 934100 517584 633114 744251 965366 1420530 1234606 782226 780539 561714 231022 1397826 1070754 737536 728448 108568 603277 368995 648035 218376 1484179 722652 1349765 597798 1051785 308415 367387 615977 1257598 790188 790274 541786 339858 970788 1476717 1763958 1822729 1805653 1240580 1519697 884813 750370 928418 1380673 1294443 794810 1357674 1999153 754931 1426931 1440078 1336691 1329777 1325866 1369550


目前在维护图像:

当前维护图像喵

我们共同见证每一位参与者的贡献!

感谢您的信任与支持!

您需要如何操作

首先,您需要先新建一个剪贴板,内容是 lgs_register_verification

然后,您可以到 这个页面 注册并登录您的 luogu.me 账号。

最后,您可以到 这个页面 申请您的 accesskey 并告诉我,以及,别忘了告诉我您的洛谷 UID 和要维护的图像!

注意,您不需要把您的用户登录 Token 给我!!!

同时,本次绘版会在开始(春节)前 10 天重置所有 accesskey,请务必在重置后将其重新发给我。

一起向未来

于此公开封装过的客户端。

C++
#include<websocketpp/config/asio_client.hpp>
#include<websocketpp/client.hpp>
#include<boost/asio/steady_timer.hpp>
#include<boost/beast/core/flat_buffer.hpp>
#include<boost/endian/conversion.hpp>
#include<nlohmann/json.hpp>
#include<bits/extc++.h>
#define STB_IMAGE_IMPLEMENTATION
#include<stb_image.h>
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include<stb_image_resize.h>
using namespace std;
struct Color{
	uint8_t r,g,b;
	Color(uint8_t _r=0,uint8_t _g=0,uint8_t _b=0):r(_r),g(_g),b(_b){}
	bool operator!=(const Color&x)const{return abs(r-x.r)>9||abs(g-x.g)>9||abs(b-x.b>9);}
};
Color bd[1000][600];
mutex bdlck;
void getPaintboard(){
	//system("curl -s \"https://paintboard.luogu.me/api/paintboard/getboard\" --output board.tmp");
	vector<uint8_t>buffer;
	const size_t BUFFER_SIZE=4096;
	uint8_t temp[BUFFER_SIZE];
	size_t read_bytes;
	freopen("board.tmp","rb",stdin);
	while((read_bytes=fread(temp,1,BUFFER_SIZE,stdin))>0)buffer.insert(buffer.end(),temp,temp+read_bytes);
	fclose(stdin);
	const size_t EXPECTED_SIZE=600*1000*3;
	if(buffer.size()!=EXPECTED_SIZE)throw runtime_error("数据长度异常:实际读取"+to_string(buffer.size())+"字节,预期"+to_string(EXPECTED_SIZE)+"字节");
	lock_guard<mutex>lock(bdlck);
	for(int y=0;y<600;++y){
		for(int x=0;x<1000;++x){
			size_t offset=y*1000*3+x*3;
			bd[y][x]=Color(buffer[offset],buffer[offset+1],buffer[offset+2]);
		}
	}
	cerr<<"获取版面数据成功\n";
}
Color exbd[1000][600];
bitset<600>vis[1000];
atomic<bool>inque[1000][600];
atomic<int>outque[1000010];
atomic<int>queL{0},queR{0};
atomic<long long>paints;
struct Task{
	uint16_t x,y;
	Color color;
	uint32_t uid;
	string paintkey;
	uint32_t id;	
};
static constexpr size_t QUEUE_SIZE=1000000;
static constexpr size_t MAX_SEND_BATCH=1000;
static constexpr int BOARD_HEIGHT=600;
static constexpr int BOARD_WIDTH=1000;
static constexpr auto SEND_INTERVAL=chrono::milliseconds(4);
static constexpr auto RECONNECT_INTERVAL=chrono::seconds(0);
static constexpr size_t MAX_RECONNECT_ATTEMPTS=0;
struct PaintboardClient{
	using websocket_client=websocketpp::client<websocketpp::config::asio_tls_client>;
	using connection_hdl=websocketpp::connection_hdl;
	Task task_queue_data_[QUEUE_SIZE];
	atomic<size_t>task_queue_head_{0};
	atomic<size_t>task_queue_tail_{0};
	map<uint32_t,int>mp,id2uid;
	bool push_task_to_queue(const Task&task){
		size_t current_head=task_queue_head_.load(memory_order_relaxed);
		size_t next_head=(current_head+1)%QUEUE_SIZE;
		if(next_head==task_queue_tail_.load(memory_order_acquire))return 0;
		task_queue_data_[current_head]=task;
		task_queue_head_.store(next_head,memory_order_release);
		return 1;
	}
	size_t pop_batch_from_queue(Task*batch,size_t max_count){
		size_t current_tail=task_queue_tail_.load(memory_order_relaxed);
		size_t current_head=task_queue_head_.load(memory_order_acquire);
		size_t count=0;
		while(count<max_count&&current_tail!=current_head){
			batch[count]=task_queue_data_[current_tail];
			current_tail=(current_tail+1)%QUEUE_SIZE;
			++count;
		}
		if(count>0)task_queue_tail_.store(current_tail,memory_order_release);
		return count;
	}
	unique_ptr<websocket_client>ws_client_ptr_;
	connection_hdl ws_hdl_;
	unordered_map<uint32_t,string>uid_to_paintkey_;
	unordered_map<uint32_t,atomic<uint64_t>>uid_timestamps_;
	atomic<uint32_t>paint_id_counter_{0};
	atomic<bool>pixel_in_queue_[BOARD_HEIGHT][BOARD_WIDTH];
	mutex task_queue_mutex_;
	mutex mp_mutex_;
	uint64_t Ti_ms_;
	thread send_thread_;
	thread io_thread_;
	atomic<bool>running_{0};
	atomic<bool>connected_{0};
	atomic<bool>reconnect_needed_{0};
	atomic<size_t>reconnect_attempts_{0};
	string websocket_uri_;
	static uint64_t current_time_ms(){
		return chrono::duration_cast<chrono::milliseconds>(
					chrono::high_resolution_clock::now().time_since_epoch())
			.count();
	}
	vector<uint8_t>uuid_string_to_bytes(const string&uuid_str){
		vector<uint8_t>bytes;
		bytes.reserve(16);
		string clean_uuid=uuid_str;
		clean_uuid.erase(remove(clean_uuid.begin(),clean_uuid.end(),'-'),clean_uuid.end());
		if(clean_uuid.size()!=32){
			cerr<<"Invalid UUID string length: "<<clean_uuid.size()<<", expected 32."<<endl;
			return bytes;
		}
		for(size_t i=0;i<clean_uuid.size();i+=2){
			string byte_str=clean_uuid.substr(i,2);
			try{
				uint8_t byte_val=static_cast<uint8_t>(stoi(byte_str,nullptr,16));
				bytes.push_back(byte_val);
			}
			catch(...){
				cerr<<"Error parsing UUID byte: "<<byte_str<<endl;
				return vector<uint8_t>();
			}
		}
		return bytes;
	}
	vector<uint8_t>serialize_task(const Task&task){
		vector<uint8_t>buffer;
		buffer.reserve(32);
		buffer.push_back(0xfe);
		uint16_t x_le=boost::endian::native_to_little(task.x);
		uint16_t y_le=boost::endian::native_to_little(task.y);
		buffer.insert(buffer.end(),reinterpret_cast<uint8_t*>(&x_le),reinterpret_cast<uint8_t*>(&x_le)+2);
		buffer.insert(buffer.end(),reinterpret_cast<uint8_t*>(&y_le),reinterpret_cast<uint8_t*>(&y_le)+2);
		buffer.push_back(task.color.r);
		buffer.push_back(task.color.g);
		buffer.push_back(task.color.b);
		uint32_t uid_le=boost::endian::native_to_little(task.uid);
		buffer.insert(buffer.end(),reinterpret_cast<uint8_t*>(&uid_le),reinterpret_cast<uint8_t*>(&uid_le)+3);
		vector<uint8_t>pk_bytes=uuid_string_to_bytes(task.paintkey);
		if(pk_bytes.size()!=16){
			cerr<<"Failed to parse PaintKey for UID "<<task.uid<<", skipping task."<<endl;
			return{};
		}
		buffer.insert(buffer.end(),pk_bytes.begin(),pk_bytes.end());
		uint32_t id_le=boost::endian::native_to_little(task.id);
		buffer.insert(buffer.end(),reinterpret_cast<uint8_t*>(&id_le),reinterpret_cast<uint8_t*>(&id_le)+4);
		return buffer;
	}
	void initialize_websocket_client(){
		ws_client_ptr_=make_unique<websocket_client>();
		auto&ws_client=*ws_client_ptr_;
		ws_client.clear_access_channels(websocketpp::log::alevel::all);
		ws_client.init_asio();
		ws_client.set_tls_init_handler([](websocketpp::connection_hdl)
									  {return websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv12_client);});
		ws_client.set_open_handler(bind(&PaintboardClient::on_open,this,placeholders::_1));
		ws_client.set_close_handler(bind(&PaintboardClient::on_close,this,placeholders::_1));
		ws_client.set_fail_handler(bind(&PaintboardClient::on_fail,this,placeholders::_1));
		ws_client.set_message_handler(bind(&PaintboardClient::on_message,this,placeholders::_1,placeholders::_2));
	}
	void on_open(connection_hdl hdl){
		getPaintboard();
		cout<<"WebSocket connection opened."<<endl;
		ws_hdl_=hdl;
		connected_.store(1);
		reconnect_attempts_.store(0);
		reconnect_needed_.store(0);
	}
	void on_close(connection_hdl hdl){
		cout<<"WebSocket connection closed."<<endl;
		connected_.store(0);
		reconnect_needed_.store(1);
	}
	void on_fail(connection_hdl hdl){
		auto conn=ws_client_ptr_->get_con_from_hdl(hdl);
		cout<<"WebSocket connection failed: "<<conn->get_ec()<<endl;
		connected_.store(0);
		reconnect_needed_.store(1);
	}
	void handle_reconnection(){
		if(!running_.load()||!reconnect_needed_.load()){
			cerr<<"????????\n";
			return;
		}
		reconnect_needed_.store(0);
		size_t attempts=reconnect_attempts_.fetch_add(1);
		if(MAX_RECONNECT_ATTEMPTS>0&&attempts>=MAX_RECONNECT_ATTEMPTS){
			cerr<<"Maximum reconnection attempts reached. Stopping reconnection attempts."<<endl;
			running_.store(0);
			return;
		}
		cout<<"Attempt "<<attempts+1<<"  to reconnect..."<<endl;
		if(io_thread_.joinable())io_thread_.join();
		if(ws_client_ptr_){
			try{
				if(connected_.load()){
					ws_client_ptr_->close(ws_hdl_,websocketpp::close::status::going_away,"Reconnecting");
				}
				ws_client_ptr_->stop_perpetual();
				ws_client_ptr_->stop();
			}
			catch(...){
				cerr<<"cleaner error!\n";
			}
		}
		//cerr<<"kjsjdhfkjhsdf\n";
		initialize_websocket_client();
		//cerr<<"initialize finished\n";
		connect_internal();
		//cerr<<"reconnection finished\n";
	}
	void on_message(websocketpp::connection_hdl hdl,websocket_client::message_ptr msg){
		if(msg->get_opcode()==websocketpp::frame::opcode::binary){
			boost::beast::flat_buffer buffer;
			auto writable=buffer.prepare(msg->get_payload().size());
			memcpy(writable.data(),msg->get_payload().data(),msg->get_payload().size());
			buffer.commit(msg->get_payload().size());
			auto data=static_cast<const uint8_t*>(buffer.data().data());
			size_t size=buffer.size();
			size_t offset=0;
			while(offset<size){
				if(offset>=size)
					break;
				uint8_t type=data[offset++];
				switch(type){
					case 0xfc:{
						vector<uint8_t>pong_packet={0xfb};
						if(connected_.load()){
							try{
								ws_client_ptr_->send(ws_hdl_,pong_packet.data(),pong_packet.size(),websocketpp::frame::opcode::binary);
							}
							catch(const websocketpp::exception&e){
								cerr<<"Error sending pong: "<<e.what()<<endl;
							}
						}
					}break;
					case 0xfa:{
						if(offset+6<=size){
							uint16_t x=boost::endian::little_to_native(*reinterpret_cast<const uint16_t*>(data+offset));
							offset+=2;
							uint16_t y=boost::endian::little_to_native(*reinterpret_cast<const uint16_t*>(data+offset));
							offset+=2;
							uint8_t r=data[offset++];
							uint8_t g=data[offset++];
							uint8_t b=data[offset++];
							if(!inque[x][y]&&vis[x][y]&&(abs(r-exbd[x][y].r)>10||abs(g-exbd[x][y].g)>10||abs(b!=exbd[x][y].b)>10)){
								outque[queR++]=x<<16|y,inque[x][y]=1;
								if(queR>1000000)queR=0;
							}
						}
					}break;
					case 0xff:{
						if(offset+4<=size){
							uint32_t id=boost::endian::little_to_native(*reinterpret_cast<const uint32_t*>(data+offset));
							offset+=4;
							uint8_t code=data[offset++];
							string status_msg;
							switch(code){
								case 0xef:status_msg="Success";break;
								case 0xee:status_msg="Cooldown";break;
								case 0xed:status_msg="Invalid Token";break;
								case 0xec:status_msg="Bad Request";break;
								case 0xeb:status_msg="No Permission";break;
								case 0xea:status_msg="Server Error";break;
								default:status_msg="Unknown Code";break;
							}
							if(status_msg!="Success"){
								lock_guard<mutex>lock(mp_mutex_);
								int target=mp[id],x=target>>16,y=target&((1<<16)-1);
								mp.erase(id);
								id2uid.erase(id);
								uid_timestamps_[id2uid[id]]=0;
								if(!inque[x][y]){
									outque[queL--]=x<<16|y,inque[x][y]=1;
									if(queL<0)queL=1000000;
								}
							}else++paints;
						}
					}
					break;
					default:
						cout<<"Unknown message type received: 0x"<<hex<<(int)type<<dec<<endl;
						break;
				}
			}
		}
	}
	void run_send_loop(){
		while(running_.load()){
			//cerr<<"send loop!\n";
			if(!connected_.load()){
				if(reconnect_needed_.load())handle_reconnection();
				//cerr<<"recoonected\n";
				this_thread::sleep_for(chrono::milliseconds(100));
				continue;
			}
			//cerr<<"try to send\n";
			this_thread::sleep_for(SEND_INTERVAL);
			vector<uint8_t>merged_data;
			merged_data.reserve(MAX_SEND_BATCH*32);
			lock_guard<mutex>lock(task_queue_mutex_);
			Task batch[MAX_SEND_BATCH];
			size_t num_tasks=pop_batch_from_queue(batch,MAX_SEND_BATCH);
			for(size_t i=0;i<num_tasks;++i){
				const Task&t=batch[i];
				vector<uint8_t>task_data=serialize_task(t);
				if(!task_data.empty()){
					merged_data.insert(merged_data.end(),task_data.begin(),task_data.end());
					pixel_in_queue_[t.y][t.x].store(0);
				}
			}
			//cerr<<"merged!\n";
			if(!merged_data.empty()&&connected_.load()){
				try{
					ws_client_ptr_->send(ws_hdl_,merged_data.data(),merged_data.size(),websocketpp::frame::opcode::binary);
				}
				catch(const websocketpp::exception&e){
					cerr<<"Error sending merged data: "<<e.what()<<endl;
					connected_.store(0);
					reconnect_needed_.store(1);
				}
			}
			//cerr<<"sended\n";
		}
		//cerr<<"sendlopsdfihousdfgjkhdfgjhkdfg\n";
		exit(-1);
	}
	PaintboardClient(const unordered_map<uint32_t,string>&uid_pk_map,uint64_t Ti_milliseconds,const string&uri="wss://paintboard.luogu.me/api/paintboard/ws"):uid_to_paintkey_(uid_pk_map),Ti_ms_(Ti_milliseconds),websocket_uri_(uri){
		for(int y=0;y<BOARD_HEIGHT;++y){
			for(int x=0;x<BOARD_WIDTH;++x){
				pixel_in_queue_[y][x].store(0);
			}
		}
		uint64_t initial_time=current_time_ms()-Ti_milliseconds;
		for(const auto&pair:uid_pk_map)uid_timestamps_[pair.first].store(initial_time);
		initialize_websocket_client();
		running_.store(1);
		send_thread_=thread(&PaintboardClient::run_send_loop,this);
	}
	~PaintboardClient()
	{
		running_.store(0);
		if(send_thread_.joinable())
		{
			send_thread_.join();
		}
		if(ws_client_ptr_&&connected_.load())
		{
			try
			{
				ws_client_ptr_->close(ws_hdl_,websocketpp::close::status::going_away,"Client shutdown");
			}
			catch(...)
			{
			}
		}
		if(io_thread_.joinable())
		{
			io_thread_.join();
		}
		if(ws_client_ptr_)
		{
			try
			{
				ws_client_ptr_->stop_perpetual();
				ws_client_ptr_->stop();
			}
			catch(...)
			{
			}
		}
	}
	void connect_internal(){
		websocketpp::lib::error_code ec;
		auto con=ws_client_ptr_->get_connection(websocket_uri_,ec);
		if(ec){
			cerr<<"Could not create connection because: "<<ec.message()<<endl;
			reconnect_needed_.store(1);
			return;
		}
		try{
			ws_client_ptr_->connect(con);
			io_thread_=thread([&](){ws_client_ptr_->run();});
		}
		catch(const websocketpp::exception&e){
			cerr<<"Error during connection: "<<e.what()<<endl;
			reconnect_needed_.store(1);
		}
	}
	void connect(const string&uri_str="wss://paintboard.luogu.me/api/paintboard/ws"){
		websocket_uri_=uri_str;
		connect_internal();
	}
	bool add_task(uint16_t x,uint16_t y,Color color){
		if(x>=BOARD_WIDTH||y>=BOARD_HEIGHT){
			cerr<<"Invalid coordinates ("<<x<<", "<<y<<"). Must be within [0, 1000) x [0, 600)."<<endl;
			return 0;
		}
		lock_guard<mutex>lock(task_queue_mutex_);
		if(pixel_in_queue_[y][x].load()){
			return 1;
		}
		if(uid_to_paintkey_.empty()){
			cerr<<"No UIDs available in the map."<<endl;
			return 0;
		}
		//cerr<<"adding task "<<x<<' '<<y<<'\n';
		uint32_t selected_uid=0;
		uint64_t earliest_timestamp=numeric_limits<uint64_t>::max();
		bool found=0;
		for(const auto&pair:uid_to_paintkey_){
			uint32_t uid=pair.first;
			uint64_t timestamp=uid_timestamps_[uid].load();
			if(!found||timestamp<earliest_timestamp){
				earliest_timestamp=timestamp;
				selected_uid=uid;
				found=1;
			}
		}
		if(!found)
			return 0;
		auto it=uid_to_paintkey_.find(selected_uid);
		if(it==uid_to_paintkey_.end())
			return 0;
		const string&paintkey=it->second;
		auto&timestamp_ref=uid_timestamps_[selected_uid];
		uint64_t last_time=timestamp_ref.load();
		uint64_t earliest_allowed_time=last_time+Ti_ms_;
		uint64_t now=current_time_ms();
		if(now<earliest_allowed_time)return 0;
		pixel_in_queue_[y][x].store(1);
		uint32_t id=paint_id_counter_.fetch_add(1);
		lock_guard<mutex>lock1(mp_mutex_);
		mp[id]=x<<16|y;
		id2uid[id]=selected_uid;
		Task new_task={x,y,color,selected_uid,paintkey,id};
		if(!push_task_to_queue(new_task)){
			pixel_in_queue_[y][x].store(0);
			cerr<<"Task queue is full, cannot add task for ("<<x<<",, "<<y<<"))."<<endl;
			return 0;
		}
		timestamp_ref.store(now);
		return 1;
	}
	bool is_connected()const{return connected_.load();}
	void wait_for_connection(){
		while(running_.load()&&!is_connected()){
			this_thread::sleep_for(chrono::milliseconds(100));
			if(reconnect_needed_.load()){
				handle_reconnection();
				this_thread::sleep_for(RECONNECT_INTERVAL);
			}
		}
	}
};
vector<vector<Color>>read_image(const string&filename,int targetpixels=0){
	int width=0,height=0,channels=0;
	unsigned char*data=nullptr;
	try{
		data=stbi_load(filename.c_str(),&width,&height,&channels,0);
		if(!data)throw runtime_error("Failed to load image: "+filename+" - "+stbi_failure_reason());
		if(targetpixels){
			int nwpixels=width*height;
			double factor=sqrtl(targetpixels*1.0/nwpixels);
			const int target_width=ceil(width*factor);
			const int target_height=ceil(height*factor);
			unsigned char*resized_data=(unsigned char*)malloc(target_width*target_height*channels);
			if(!resized_data){
				stbi_image_free(data);
				throw runtime_error("Memory allocation failed for resized image");
			}
			stbir_resize_uint8(data,width,height,0,resized_data,target_width,target_height,0,channels);
			stbi_image_free(data);
			data=resized_data;
			width=target_width;
			height=target_height;
		}
		if(channels<3){
			throw runtime_error("Image must have at least 3 channels (RGB)");
		}
		vector<vector<Color>>result(height,vector<Color>(width));
		for(int y=0;y<height;++y){
			for(int x=0;x<width;++x){
				unsigned char*pixel=data+(y*width+x)*channels;
				result[y][x]=Color(pixel[0],pixel[1],pixel[2]);
			}
		}
		return result;
	}catch(const exception&e){
		if(data)stbi_image_free(data);
		throw;
	}
}
void guarder(){
	int cnt=0;
	long long lst=-1e18;
	int flg=0;
	while(cnt<=60*20){
		this_thread::sleep_for(chrono::seconds(1));
		++cnt;
		if((paints<=lst+1000&&paints>=100)||!paints){
			++flg;
			cerr<<flg<<'\n';
			if(flg>30)exit(0);
		}else flg=0;
		lst=paints;
		cerr<<paints*1.0/cnt<<" pps"<<'\n';
	}
	exit(0);
}
int main(){
	thread guard(guarder);
	guard.detach();
#ifdef _WIN32
	WSADATA wsaData;
	if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0){
		cerr<<"WSAStartup failed"<<endl;
		return 1;
	}
#endif
	const int TSZ=1000;
	ifstream f1("savedtokens.txt");
	unordered_map<uint32_t,string>uid_pk_map;
	vector<int>v;
	while(!f1.eof())
	{
		int a;
		string b;
		f1>>a>>b;
		if(a>0&&a<1e7)uid_pk_map[a]=b,v.push_back(a);
		else break;
	}
	f1.close();
	ifstream f2("Tokens.txt");
	int num;f2>>num;
	while(num--){
		string name;int a,b,c;
		f2>>name>>a>>b>>c;
		vector<vector<Color>>nw=read_image(name,c*TSZ);
		if(nw.empty()||nw[0].empty())return cerr<<"error when reading image files!\n",0;
		for(int i=a;i<a+nw[0].size()&&i<1000;++i){
			for(int j=b;j<b+nw.size()&&j<600;++j){
				exbd[i][j]=nw[j-b][i-a];
				vis[i][j]=1;
			}
		}
	}
	f2.close();
	int interval;
	ifstream fconfig("config.txt");
	fconfig>>interval;fconfig.close();
	PaintboardClient client(uid_pk_map,interval);
	cerr<<"fuck\n";
	client.connect();
	client.wait_for_connection();
	cout<<"connected!"<<endl;
	for(int i=0;i<1000;++i){
		lock_guard<mutex>lock(bdlck);
		for(int j=0;j<600;++j){
			if(vis[i][j]&&exbd[i][j]!=bd[i][j]){
				while(!client.add_task(i,j,exbd[i][j]));
			}
		}
	}
	chrono::high_resolution_clock::time_point st=chrono::high_resolution_clock::now();
	while(1){
		while(queL!=queR){
			int target=outque[queL++];
			if(queL>1000000)queL=0;
			int x=target>>16,y=target&((1<<16)-1);
			while(!client.add_task(x,y,exbd[x][y]));
			inque[x][y]=0;
		}
	}
	return 0;
}