Пример #1
0
		/// <summary>
		/// 游戏服务器连接事件函数
        /// 这个连接,仅说明是guard起来并连接到WEB服务器了;之后还需通过协议判断是哪个具体server起来了
		/// </summary>
		public void GameServerConnected(object sender, ClientConnectEventArgs e)
		{
			string address = e.RemoteAddress;
			int index = address.LastIndexOf(":");
			string ipAddress = address.Substring(0, index);
			int port = int.Parse(address.Substring(index + 1));
			long connectionId = e.ConnectionId;
            UInt16 GuardServers = 0;

			//游戏服务器认证开关
			if (SystemConfig.Current.NeedGuardAuthorization)
			{
				GameServerAuthentication auth = new GameServerAuthentication(connectionId, ipAddress, port, SystemConfig.Current.GuardAuthorizationTimeout);
				lock (_authenticationList.SyncRoot)
				{
					_authenticationList.Add(auth);
				}
				auth.Begin();
			}
			else
			{
                GameServer svr = null;
                string[] para = new string[16];
                for(int i=0;i<16;i++)
                {
                    para[i] = "0";
                }

				lock (_gameServerList.SyncRoot)
				{
					foreach (GameServer server in _gameServerList)
					{
						lock (server)
						{
							if (server.IpAddress  == ipAddress)
							{
                                if (svr == null) svr = server;
                                GuardServers++;
								if (!server.IsConnected)
								{
									server.OnConnected(connectionId, new byte[] { 1 }, port);
									//return;
								}

                                switch (server.Type)
                                {
                                    case GameServer.ServerType.goddess:
                                        para[0] = server.Id.ToString();
                                        break;
                                    case GameServer.ServerType.bishop:
                                        para[1] = server.Id.ToString();
                                        break;
                                    case GameServer.ServerType.gamecenter:
                                        para[2] = server.Id.ToString();
                                        break;
                                    case GameServer.ServerType.logserver:
                                        para[3] = server.Id.ToString();
                                        break;
                                    case GameServer.ServerType.gameserver:
                                        if (server.Name.IndexOf("01") > 0) para[4] = server.Id.ToString();
                                        else if (server.Name.IndexOf("02") > 0) para[5] = server.Id.ToString();
                                        else if (server.Name.IndexOf("03") > 0) para[6] = server.Id.ToString();
                                        else if (server.Name.IndexOf("04") > 0) para[7] = server.Id.ToString();
                                        else if (server.Name.IndexOf("05") > 0) para[8] = server.Id.ToString();
                                        else if (server.Name.IndexOf("06") > 0) para[9] = server.Id.ToString();
                                        else if (server.Name.IndexOf("07") > 0) para[10] = server.Id.ToString();
                                        else if (server.Name.IndexOf("08") > 0) para[11] = server.Id.ToString();
                                        else if (server.Name.IndexOf("09") > 0) para[12] = server.Id.ToString();
                                        else if (server.Name.IndexOf("10") > 0) para[13] = server.Id.ToString();
                                        else if (server.Name.IndexOf("11") > 0) para[14] = server.Id.ToString();
                                        else if (server.Name.IndexOf("12") > 0) para[15] = server.Id.ToString();
                                        break;
                                }
							}
						}
					}
				}

                if (svr != null)   svr.DoPlugInAction(SecurityManager.SystemAutomationId, E2gServerid.PlugInGuid, E2gServerid.actionKey, para);

				//断开没有记录的连接
                if (GuardServers == 0) 
				    AdminServer.TheInstance.ConnectionManager.Disconnect(connectionId);                
			}
		}
Пример #2
0
		/// <summary>
		/// 分发认证消息
		/// </summary>
		/// <param name="authentication">服务器认证</param>
		/// <param name="msgBuff">消息</param>
		private void DispatchAuthentication(GameServerAuthentication authentication, byte[] msgBuff)
		{
			if (authentication == null || msgBuff == null)
				return;

			ProtocolDef protocalId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 0);
			IProtocol message = null;
			switch (protocalId)
			{
				case ProtocolDef.g2e_Authentication_def:
					message = new g2e_Authentication();
                    message.FromBytes(msgBuff);
					break;
				//default:
				//throw new Exception("收到不应该在认证阶段发送的协议包");
			}

			if (message != null)
			{
				authentication.Authentication(message);
			}
		}