<?php

/**
 * 模拟客户端测试给服务器发送消息
 * Created On 2021/11/1
 * @author yuanb yuanbo0x@gmail.com
 */

namespace Test;

require_once __DIR__ . '/../Framework/AutoLoad.php';

use Framework\Protobuf\WebRequestMessage;
use Framework\Protobuf\SinglePacket;
use Game\Protobuf\CGBuyZLExpert;
use Game\Protobuf\CGBuyZLLevel;
use Game\Protobuf\CGDailyInfo;
use Game\Protobuf\CGDailyTaskOption;
use Game\Protobuf\CGDrivingLicense;
use Game\Protobuf\CGDrivingLicenseChapter;
use Game\Protobuf\CGDrivingLicenseChapterReward;
use Game\Protobuf\CGDrivingLicenseLevelReward;
use Game\Protobuf\CGEnterPve;
use Game\Protobuf\CGFinishPve;
use Game\Protobuf\CGHeartBeat;
use Game\Protobuf\CGMailOption;
use Game\Protobuf\CGMailSearch;
use Game\Protobuf\CGSubmitTask;
use Game\Protobuf\CGTaskSearch;
use Game\Protobuf\CGZLInfo;
use Game\Protobuf\CGZLReward;
use Game\Protobuf\PacketId;
use Game\Protobuf\PlayerMark;
use Game\Protobuf\PvpHeartBeatSend;
use Game\Protobuf\TaleTarget;
use Game\Protobuf\UpdateSkillEnergySend;

const URL = "http://zone3.ng.com/GameIndex.php";
const PLAYER_ID = 1111;
$message = new WebRequestMessage();
$message->setIndex(11);
$message->setServerId(1);
$message->setSession('6273c2231c7d05.05987530');
$message->setPlayerId(PLAYER_ID);
//心跳
//$packet = new CGHeartBeat();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_HeartBeat);
//$single_packet->setData($packetStr);
//PVP心跳
//$packet = new PvpHeartBeatSend();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::PVP_HeartBeat);
//$single_packet->setData($packetStr);

//能量
//$packet = new UpdateSkillEnergySend();
//$packet->setNum(1);
//$packet->setIsAdd(true);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::Skill_energy_Send);
//$single_packet->setData($packetStr);

//排位
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::Paiwei_Level_Send);
//$single_packet->setData("");

//邮件--获取全部
//$packet = new CGMailSearch();
//$packet->setStart(0);
//$packet->setEnd(9);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_MailSearch);
//$single_packet->setData($packetStr);

//$uid = 1729523404070354618;
//$packet = new CGMailOption();
//单个邮件--已读
//$packet->setOption(1);
//单个邮件--领附件
//$packet->setOption(2);
//单个邮件--删除
//$packet->setOption(3);
//删除全部已读邮件
//$packet->setOption(4);
//领取全部附件
//$packet->setOption(5);
//$packet->setMailId($uid);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_MailOption);
//$single_packet->setData($packetStr);

//任务--查询
//$packet = new CGTaskSearch();
//$packet->setType(4);    //任务类型 1日常 2支线 3主线 4战令
//$packet->setCarTplId(0);
//$packet->setWeek(0);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_TaskSearch);
//$single_packet->setData($packetStr);
//日常--获取
//$packet = new CGDailyInfo();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_DailyInfo);
//$single_packet->setData($packetStr);
//日常--提交任务/领奖
//$packet = new CGDailyTaskOption();
//$packet->setOption(2);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_DailyTaskOption);
//$single_packet->setData($packetStr);
//$taskId = 50001;
////提交任务
//$packet = new CGSubmitTask();
//$packet->setTaskId($taskId);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_SubmitTask);
//$single_packet->setData($packetStr);

//战令--获取
//$packet = new CGZLInfo();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_ZLInfo);
//$single_packet->setData($packetStr);
//战令--购买等级
//$packet = new CGBuyZLLevel();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_BuyZLLevel);
//$single_packet->setData($packetStr);
//战令--开通高级
//$packet = new CGBuyZLExpert();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_BuyZLExpert);
//$single_packet->setData($packetStr);
//战令--领取奖励
//$packet = new CGZLReward();
//$packet->setOption(3);
//$packet->setId(2);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_ZLReward);
//$single_packet->setData($packetStr);

//驾照
//驾照信息
//$packet = new CGDrivingLicense();
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_DrivingLicense);
//$single_packet->setData($packetStr);
//驾照关卡
//$packet = new CGDrivingLicenseChapter();
//$packet->setDrivingLicenseLv(0);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_DrivingLicenseChapter);
//$single_packet->setData($packetStr);
//驾照关卡领奖
//$packet = new CGDrivingLicenseLevelReward();
//$packet->setLevelId(30011);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_DrivingLicenseLevelReward);
//$single_packet->setData($packetStr);
//驾照大奖
//$packet = new CGDrivingLicenseChapterReward();
//$packet->setDrivingLicenseLv(1);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_DrivingLicenseChapterReward);
//$single_packet->setData($packetStr);
//进入pve关卡
//$packet = new CGEnterPve();
//$packet->setLevelId(30012);
//$packet->setCarTplId(1);
//$packetStr = base64_encode($packet->serializeToString());
//$single_packet = new SinglePacket();
//$single_packet->setId(PacketId::CG_EnterPve);
//$single_packet->setData($packetStr);
//pve关卡结算
$player = new PlayerMark();
$player->setPlayerId(PLAYER_ID);
$player->setRank(1);
$player->setCarId(1001);
$player->setCostTime(100);
//$player->setGroupId(0);
$playerList = array($player);
$target = new TaleTarget();
$target->setCostTime(71000);
$target->setRank(1);
$packet = new CGFinishPve();
$packet->setLevelId(30012);
$packet->setPlayerList($playerList);
$packet->setTarget($target);
$packetStr = base64_encode($packet->serializeToString());
$single_packet = new SinglePacket();
$single_packet->setId(PacketId::CG_FinishPve);
$single_packet->setData($packetStr);


$message->setPacketList([$single_packet]);
$packet_str = $message->serializeToString();

$curl = curl_init(URL);
$options = array(
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $packet_str,
    CURLOPT_HEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 3
);
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
echo base64_encode($response)."\n";