Пример #1
0
	public override void Init()
	{
		instance = this;
		clients = new ClientNode[CConstVar.MAX_CLIENTS];
		for(int i = 0; i < CConstVar.MAX_CLIENTS; i++){
			clients[i] = new ClientNode();
		}
		svEntities = new SvEntityState[CConstVar.MAX_GENTITIES];
		for(int i = 0; i < CConstVar.MAX_GENTITIES; i++){
			svEntities[i] = new SvEntityState();
		}
		// gEntities = new SharedEntity[CConstVar.MAX_GENTITIES];
		// for(int i = 0; i < CConstVar.MAX_GENTITIES; i++){
		// 	gEntities[i] = new SharedEntity();
		// }
		worldSectors = new WorldSector[64];
		for(int i = 0; i < 64; i++){
			worldSectors[i] = new WorldSector();
		}

		configString = new string[CConstVar.MAX_CONFIGSTRINGS];
		serverRunning = false;

		challenges = new SvChallenge[CConstVar.MAX_CHALLENGES];
		for(int i = 0; i < CConstVar.MAX_CHALLENGES; i++){
			challenges[i] = new SvChallenge();
		}

		numSnapshotEntities = CConstVar.MAX_CLIENTS * CConstVar.PACKET_BACKUP * CConstVar.MAX_SNAPSHOT_ENTITIES;
		snapshotEntities = new EntityState[numSnapshotEntities];
		inited = true;
	}
Пример #2
0
	private void SVCGetChallenge(IPEndPoint from){
		int i;
		int oldest = 0;
		int oldestTime = 0x7fffffff;
		var userinfo = CDataModel.CmdBuffer.Argv(1);
		var tmp = CUtils.GetValueForKey(userinfo, "port");
		if(!string.IsNullOrEmpty(tmp)){
			from.Port = System.Convert.ToInt32(tmp);
		}

		SvChallenge challenge = challenges[0];

		//查看这个ip是否已经有一个challenge
		for(i = 0; i < CConstVar.MAX_CHALLENGES; i++){
			challenge = challenges[i];
			if(!challenge.connected && from.Equals(challenge.adr)){
				break;
			}
			if(challenge.time < oldestTime){
				oldestTime = challenge.time;
				oldest = i;
			}
		}

		if(i == CConstVar.MAX_CHALLENGES){
			challenge = challenges[oldest];

			//客户端第一次请求challenge
			challenge.challenge = (CUtils.Random() << 16 ^ CUtils.Random() ) ^ time;
			challenge.adr = from;
			challenge.firstTime = time;
			challenge.time = time;
			challenge.connected = false;
			i = oldest;
		}

		if(CNetwork.IsLANAddress(from.Address)){
			challenge.pingTime = time;
			CNetwork_Server.Instance.OutOfBandSend(NetSrc.SERVER, from, "challengeResponse " + challenge.challenge + " \\port$"+CConstVar.ServerPort);
			return;
		}
		// if(authorizeAddress.Address)
	}