网游练习总结(2)

php获取js变量:document.write(string);

日前一段时间在校也闲得没事干,反正是好长一段时间,干脆就是开一个《中国象棋》网游耍耍打发时光。弄了旷日持久没写总结,以及一切过程遭到碰到的题材,今天就抢写一哈,难免后面就是会遗忘了。

$name="
        <script type='text/javascript'>
        document.write(getName());
            function getName(){
                var str=window.location.search;
                var args=str.split('?');
                 var retval='';
                 if(args[0]==str){return '';}//参数为空;
                 return args[1].split('=')[1];
                }
        </script>";
//其实这样是得到了变量,但也其实是一个啰嗦,可以直接用$_GET['KEY']得到。

平、注册登录界面:

AS3.0获取php变量

   
可能会见说这样简单的游乐,网上或例子很多,也无必要将注册这样的力量,其实我单是学在玩玩哈。

//------signClass-------
//加载目标php文件函数:
private function loaded(event:Event):void
        {
            if(this.data.strings)
            {
                var str:String=this.data.strings;
                var arr=this.data.strings.split("<br/>");

                trace(arr[0].split("name=")[1]);
                trace(arr[1].split("pasd=")[1]);
                trace(arr[2].split("mail=")[1]);
                trace(arr[3].split("sign=")[1]);

                if(arr[3].split("sign=")[1]=="succeed")
                {
                    this.isSign=true;
                    info=Singleton.GetSingleton(UserInfo as Class);
                    info.user_pswd=arr[1].split("pasd=")[1];
                    info.userEmail=arr[2].split("mail=")[1];
                    info.userName =arr[0].split("name=")[1];

                    this.father.SIGNED=this.father.STATES["succeed"];
                }else if(arr[3].split("sign=")[1]=="faild"){
                    trace("运行到此处");
                    this.isSign=false;
                    this.father.SIGNED=this.father.STATES["faild"];
                }else
                {
                    trace("unormal");
                    this.father.SIGNED=this.father.STATES["error"];
                }
            }

            //trace(this.isSign);
        }

$sql="SELECT * FROM chinesechess WHERE user_email='{$_email}'and password='{$_paswd}' and isActivated='{$_activate}'";
    $result = mysql_query($sql,$con);
    $source=mysql_fetch_array($result);


    if($source)
    {
         $sign="succeed";

         $name=$source['nickname'];

         $pasd=$source['password'];

         $mail=$source['user_email'];

    }else
    {
         $sign="faild";

         $name="null";

         $pasd="null";

         $mail="null@cn.com";



    }
        echo 'strings=name='.$name.'<br/>';
        echo 'pasd='.$pasd.'<br/>';
        echo 'mail='.$mail.'<br/>';
        echo 'sign='.$sign.'<br/>';

有关注册我动用的凡php与as3.0互相做的,有同php学的不可开交浅,也遇上了很多问题:

as3.0落后台数据必须下台出口的键值对之明白来获取。

1.检测是否注册成功:这个为累了时未是挺丰富,但是觉得比根本,我搜了部分材料找到的:

php获取AS3.0变量

mysql_affected_rows()// 函数返回前一次 MySQL 操作所影响的记录行数。执行成功,则返回受影响的行的数目,如果最近一次查询失败的话,函数返回 -1。
/*
         *@function :  public   signClass  构造函数
         *@parameter:
         *  path      String    php文件路径    
         *  obj       Main      Main类
         *  email     String    邮件字符串    "NULL"
         *  password  String    密码字符串    "1234"
         */
        public function signClass(path:String,obj:Sign_mc,email:String="NULL",password:String="1234")
        {
            this.father=obj;

            _var=new URLVariables();
            request=new URLRequest(path);
            request.method=URLRequestMethod.POST;

            _var._email=email;
            _var._pasd=password;

            request.data=_var;
            this.dataFormat = URLLoaderDataFormat.VARIABLES;  
            this.load(request);
            this.addEventListener(Event.COMPLETE,loaded);
            //trace(password);
        }

2.信箱激活验证:

AS3.0客户端通过 URLVariables对象就是价值为URLRequest的method=URLRequestMethod.POST方法发送给php,php端直接动用$_POST[‘_email’]取得到就是OK。

<?php
class smtp

{

/* Public Variables */

var $smtp_port;

var $time_out;

var $host_name;

var $log_file;

var $relay_host;

var $debug;

var $auth;

var $user;

var $pass;

/* Private Variables */ 
var $sock;

/* Constractor */

function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)

{

$this->debug = FALSE;

$this->smtp_port = $smtp_port;

$this->relay_host = $relay_host;

$this->time_out = 30; //is used in fsockopen() 
#

$this->auth = $auth;//auth

$this->user = $user;

$this->pass = $pass;

#

$this->host_name = "localhost"; //is used in HELO command 
$this->log_file = "";

$this->sock = FALSE;

}

/* Main Function */

function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")

{

$mail_from = $this->get_address($this->strip_comment($from));

$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);

$header = "MIME-Version:1.0\r\n";

if($mailtype=="HTML"){

$header .= "Content-Type:text/html\r\n";

}

$header .= "To: ".$to."\r\n";

if ($cc != "") {

$header .= "Cc: ".$cc."\r\n";

}

$header .= "From: $from<".$from.">\r\n";

$header .= "Subject: ".$subject."\r\n";

$header .= $additional_headers;

$header .= "Date: ".date("r")."\r\n";

$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";

list($msec, $sec) = explode(" ", microtime());

$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

$TO = explode(",", $this->strip_comment($to));

if ($cc != "") {

$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));

}

if ($bcc != "") {

$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));

}

$sent = TRUE;

foreach ($TO as $rcpt_to) {

$rcpt_to = $this->get_address($rcpt_to);

if (!$this->smtp_sockopen($rcpt_to)) {

$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");

$sent = FALSE;

continue;

}

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {

$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");

} else {

$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");

$sent = FALSE;

}

fclose($this->sock);

$this->log_write("Disconnected from remote host\n");

}

return $sent;

}

/* Private Functions */

function smtp_send($helo, $from, $to, $header, $body = "")

{

if (!$this->smtp_putcmd("HELO", $helo)) {

return $this->smtp_error("sending HELO command");

}

#auth

if($this->auth){

if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {

return $this->smtp_error("sending HELO command");

}

if (!$this->smtp_putcmd("", base64_encode($this->pass))) {

return $this->smtp_error("sending HELO command");

}

}

#

if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {

return $this->smtp_error("sending MAIL FROM command");

}

if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {

return $this->smtp_error("sending RCPT TO command");

}

if (!$this->smtp_putcmd("DATA")) {

return $this->smtp_error("sending DATA command");

}

if (!$this->smtp_message($header, $body)) {

return $this->smtp_error("sending message");

}

if (!$this->smtp_eom()) {

return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");

}

if (!$this->smtp_putcmd("QUIT")) {

return $this->smtp_error("sending QUIT command");

}

return TRUE;

}

function smtp_sockopen($address)

{

if ($this->relay_host == "") {

return $this->smtp_sockopen_mx($address);

} else {

return $this->smtp_sockopen_relay();

}

}

function smtp_sockopen_relay()

{

$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");

$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);

if (!($this->sock && $this->smtp_ok())) {

$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");

$this->log_write("Error: ".$errstr." (".$errno.")\n");

return FALSE;

}

$this->log_write("Connected to relay host ".$this->relay_host."\n");

return TRUE;;

}

function smtp_sockopen_mx($address)

{

$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);

if (!@getmxrr($domain, $MXHOSTS)) {

$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");

return FALSE;

}


foreach ($MXHOSTS as $host) {

$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");

$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);

if (!($this->sock && $this->smtp_ok())) {

$this->log_write("Warning: Cannot connect to mx host ".$host."\n");

$this->log_write("Error: ".$errstr." (".$errno.")\n");

continue;

}

$this->log_write("Connected to mx host ".$host."\n");

return TRUE;

}

$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");

return FALSE;

}

function smtp_message($header, $body)

{

fputs($this->sock, $header."\r\n".$body);

$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));

return TRUE;

}

function smtp_eom()

{

fputs($this->sock, "\r\n.\r\n");

$this->smtp_debug(". [EOM]\n");

return $this->smtp_ok();

}

function smtp_ok()

{

$response = str_replace("\r\n", "", fgets($this->sock, 512));

$this->smtp_debug($response."\n");

if (!ereg("^[23]", $response)) {

fputs($this->sock, "QUIT\r\n");

fgets($this->sock, 512);

$this->log_write("Error: Remote host returned \"".$response."\"\n");

return FALSE;

}

return TRUE;

}

function smtp_putcmd($cmd, $arg = "")

{

if ($arg != "") {

if($cmd=="") $cmd = $arg;

else $cmd = $cmd." ".$arg;

}

fputs($this->sock, $cmd."\r\n");

$this->smtp_debug("> ".$cmd."\n");

return $this->smtp_ok();

}

function smtp_error($string)

{

$this->log_write("Error: Error occurred while ".$string.".\n");

return FALSE;

}

function log_write($message)

{

$this->smtp_debug($message);

if ($this->log_file == "") {

return TRUE;

}

$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;

if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {

$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");

return FALSE;;

}

flock($fp, LOCK_EX);

fputs($fp, $message);

fclose($fp);


return TRUE;

}


function strip_comment($address)

{

$comment = "\([^()]*\)";

while (ereg($comment, $address)) {

$address = ereg_replace($comment, "", $address);

}


return $address;

}


function get_address($address)

{

$address = ereg_replace("([ \t\r\n])+", "", $address);

$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);

return $address;

}

function smtp_debug($message)

{

if ($this->debug) {

echo $message;

}

}

}

?>

phpMyAdmin中装置主键和A_I:在新建数据表里面其实就得设置A_I,但是好像并不曾找到设置主键的钥匙按钮,后来才发现凡是自身的多寡中的[结构]这就是说无异圈不明白怎么老是从不起来,偶然打开了同不良,设置主键的按钮在就同一苑中,真是害得自好辛苦。然后就是不知情怎么处理多少插入失败后再次插入成功之时节主键增长的时刻回将失败的次数为算算算在里面,最后我以php端直接以砸的底操作该屏蔽掉了才解决了这个题目,但我想应该发更好之办法吧。

斯要配备SMTP服务,现在QQ邮箱网易邮箱等还足以去装,然后作为代理邮箱。

 

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
$smtp->debug = false;//关闭调试
$state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);

二.服务器端:

以整数据库操作过程中采用一个变量来监督是否出现操作不当,来回到是否报成功;

一日游服务器其实是自身借别人的,只是当基础及冲自己待改了一部分。

error_reporting(E_ERROR | E_WARNING | E_PARSE);//屏蔽所有错误警告等

1.swf客户端连接到服务端:相信swf客户端连接到服务端好多总人口都十分头疼,我当好几独flash群里面遇到了众多有关安全沙箱问题,以及socket连接。其实要安全策略文件配置不错一般都没有问题,还有会提醒打开843端口之事态,是本土默认关闭是端口造成的。在
本地防火墙->高级设置->进站规则->新建规则
里面可以加上自己同意的端口号。

激活页面:

as3.0 socket连接到java服务端

<?php    
 header("Content-Type:text/html;charset=utf-8");

     require_once "sendEmail/mysqlInfo/sqlInfo.php";
     $name=base64_decode($_GET['isdhf']);

      if($name=="")
      {
          exit();
      }else{


     $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD)or die('连接错误');
       //选择数据库
       mysql_select_db(DB_NAME,$con)or die('Occured error');
       mysql_query('SET NAMES UTF8') or die('显示错误');

        $sql="SELECT isActivated FROM chinesechess WHERE nickname='{$name}'";
        //$row=@mysql_query($query) or die('error');
        $result=mysql_query($sql,$con)or die('error');
       //关闭数据库
        $arr=mysql_fetch_array($result);
        if($arr['isActivated']=='0')
        {
          //如果没有激活,就输出激活页面,否则网页不存在;
echo 
'<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/index_CSS.css" />
<style type="text/css">
body,td,th {
    font-size: xx-large;
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
</style>
<title>游戏注册[欢迎注册]</title>
  <script type="text/javascript">
                   function havedActivate()
                   {
                       var name=document.getElementById("nickname").title;
                       window.location.href="activated.php?key="+name;
                   }
        </script>
</head>

<body>
 <div id="tDiv">
   <table>
  <td></td>
   </table>
   <h2>账户激活</h2>
   <p>&nbsp;</p>
   <table width="100%" border="0">
     <tr>
       <td id="tDL"><p>您的随机昵称为:<label id="nickname" title="'.$name.'">"'.$name.'"</label></p>
       <p>&nbsp;</p></td>
     </tr>
     <tr>
       <td align="center" id="tDL">
         <p>
           <input type="submit" value="确认激活" id="activateBtn" onClick="havedActivate();"/>
         </p>
       </td>
     </tr>
   </table>
   <p>&nbsp;</p>
 </div>
</body>
</html>';
            }else
            {
                echo "该网页不存在";
            }
    mysql_close();
    }
?>

<?php 
  header("Content-Type:text/html;charset=utf-8");

    require_once "sendEmail/mysqlInfo/sqlInfo.php";

    error_reporting(E_ERROR | E_WARNING | E_PARSE);//禁止显示错误警号等


    $name=$_GET['key'];
    if($name=="")
    {
        exit();
    }else
    {
       $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD)or die('连接错误');
       //选择数据库
       mysql_select_db(DB_NAME,$con)or die('Occured error');
       mysql_query('SET NAMES UTF8') or die('显示错误');

        $sql="UPDATE chinesechess SET isActivated='1' WHERE nickname='{$name}'";
        $result = mysql_query($sql,$con) or die('error');
       //关闭数据库

    mysql_close();
 echo'<html>
    <head>
        <meta charset="utf-8" />
        <title>账号已激活</title>
        <link rel="stylesheet" href="css/index_CSS.css" />';
        $name="
        <script type='text/javascript'>
        document.write(getName());
            function getName(){
                var str=window.location.search;
                var args=str.split('?');
                 var retval='';
                 if(args[0]==str){return '';}//参数为空;
                 return args[1].split('=')[1];
                }
        </script>";
    echo '</head>
    <body>
    <div id="tDiv">
   <table>
  <td></td>
   </table>
   <h2>账户已激活</h2>
   <p>&nbsp;</p>
   <table width="100%" border="0">
     <tr>
       <td id="tDL"><p>您的随机昵称为:<label>'.$name.'</label></p>
       <p>&nbsp;</p></td>
     </tr>
     <tr>
       <td align="center" id="tDL">
         <p>
           <p><font color="#FF0000">您的账号已激活,祝您游戏愉快!</font></p>
         </p>
       </td>
     </tr>
   </table>
   <p>&nbsp;</p>
 </div>

    </body>
</html>';
      }



?>
//ServerThread .java


package com.feiruo.Chess;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerThread extends Thread
{
     Server       father;
     boolean      tag=true;
     String       xmlString="<cross-domain-policy>";
     ServerSocket ss;

     public ServerThread(Server server)
     {
         this.father=server;
         this.ss=father.ss;

         this.xmlString="<?xml version=\"1.0\"?>" +   
                 "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">" +   
                     "<cross-domain-policy>" +   
                     "<allow-access-from domain=\"*\" to-ports=\"8082\" />" +   
                     "</cross-domain-policy>\0"; 

     }
     public void run()
     {
        while (this.tag)
        {
            try
            {
                //等待连接:
                Socket sc=ss.accept();
                BufferedReader br = new BufferedReader(new InputStreamReader(sc.getInputStream()));
                PrintWriter pw = new PrintWriter(sc.getOutputStream());
                char[] by = new char[22];
                br.read(by,0,22);
                String msghead = new String(by);
                // System.out.println(msghead);
                if (msghead.startsWith("<policy-file-request/>"))
                {
                    pw.print(this.xmlString);
                    pw.flush();
                }
                else 
                {
                    //开启代理线程
                    ServerAgentThread sat=new ServerAgentThread(this.father, sc);
                   // System.out.println("已发送");
                    sat.start();
                    sat.dou.writeUTF("<#CONNECTED#>");
                    sat.dou.flush();
                    sat.tag=true;

                   // System.out.println("IP:"+sc.getInetAddress());
                }
            } catch (Exception e)
            {
               this.tag=false;    
            }

        }
     }
}

CSS:

检测客户端是不是断开连接

@charset "utf-8";
/* CSS Document */
h2{
    font-size:56px;
    font-weight:bold;
    text-align:center;
}
body{
    width:auto;
    height:auto;
    background-image:url(...png);
    background-repeat:no-repeat;
    background-size:100% 100%;
    background-attachment:fixed;
    background-position:center;
}
#tDiv{
    background-image:url(..o1.png);
    background-repeat:repeat;
    margin-left:auto;
    margin-right:auto;
    margin-top:200px;
    width:550px;
    height:auto;
    font-size:10px;
    border:2px solid #CCC;
}
#tDL{
    font-size:24px;
    text-align:center;
}
//检测出客户端是否断网或者离线
            try { 
                sc.sendUrgentData(0); 
                } catch (IOException e) 
                { 
                    this.client_leave("<#CLIENT_LEAVE#>"+this.getName());
                    tag=false;//终止该服务器代理线程
                } 

登录:

sendUrgentData方法会朝着输出流发送一个字节的多寡,只要对方Socket的SO_OOBINLINE属性没有打开,就会自行放弃这个字节,而SO_OOBINLINE属性默认情况下就是关的。

<?php
     header("Content-Type:text/html;charset=utf-8");

     require_once "sendEmail/mysqlInfo/sqlInfo.php";

     error_reporting(E_ERROR | E_WARNING | E_PARSE);//禁止显示错误警号等
     $sign='';

     $_email=$_POST['_email'];    
     $_paswd=$_POST['_pasd'];
//     $_email="2810718058@qq.com";
//     $_paswd="1234567890";
     $_activate='1';  //激活变量
     //连接数据库
     $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD)or die('连接错误');

     mysql_select_db(DB_NAME,$con)or die('Occured error');
     mysql_query('SET NAMES UTF8') or die('显示错误');

    $sql="SELECT * FROM chinesechess WHERE user_email='{$_email}'and password='{$_paswd}' and isActivated='{$_activate}'";
    $result = mysql_query($sql,$con);
    $source=mysql_fetch_array($result);


    if($source)
    {
        $sign="succeed";

         $name=$source['nickname'];

         $pasd=$source['password'];

         $mail=$source['user_email'];

        echo 'strings=name='.$name.'<br/>';
        echo 'pasd='.$pasd.'<br/>';
        echo 'mail='.$mail.'<br/>';
        echo 'sign='.$sign.'<br/>';
    }else
    {
         $sign="faild";

         $name="null";

             $pasd="000000";

             $mail="null@cn.com";

        echo 'strings=name='.$name.'<br/>';
        echo 'pasd='.$pasd.'<br/>';
        echo 'mail='.$mail.'<br/>';
        echo 'sign='.$sign.'<br/>';

    }

    mysql_close();

?>

 AS3.0以setTimeout美高梅娱乐4858.com判断socket连接超时

Resource id #num

private var isResponsed:Boolean=false; 

......

 setTimeoutHandlerId=setTimeout(
                                  function():void
                                  {  
                                       if(!isResponsed)
                                       {  
                                           this.ERROR="网络连接超时,\n请重新尝试!";  
                                       }  
                                   },timeoutMs); 
this.addEventListener(Event.CONNECT,haveConnected);

......

private function setReponsedHandler(event:Event):void
{  
     isResponsed=true;  
     clearTimeout(setTimeoutHandlerId);  
}

......

public function haveConnected(event:Event):void
{           
      clearTimeout(setTimeoutHandlerId);
      this.flush();
}

由于自家是一样枚初家,对mysql查询返回值等了解不够,遇到了某些迷惑,mysql_query()
仅对 SELECT,SHOW,EXPLAIN 或 DESCRIBE
语词返回一个资源标识符,如果查询执行不科学则赶回
FALSE。要使mysql_fatch_array()函数或者mysql_fetch_object()函数进行转移,然后对相应数组或者目标进行操作。

2.数量传送

由此看来这有的遇到的艰苦为未是无数,经过协调之鼎力很快就解决了。

AS3.0读博服务器数据:这里可能遇到的题目虽是读取数据遇到文件尾。起初我用的是Socket.readUTFBytes(Socket.bytesAvailable);但是会发现读取的数量是读取了了,但是于为临时变量赋值的当儿字符串是绝对续续的,以至于后面对数据的分析和判断不怎么好开展操作。我为先期将数量存起来相当她全部念毕事后更统一后展开解析操作,但是感觉这样好烦。最后选用了Socket.readUTF()方法,但是会有遇到文件尾问题,于是自己为百度了诸多,但看来的主意感觉并无怎么抱自己,最后我思既是逢文件尾,肯定是自家本着数据发送时处理的未相宜,最后发现自家于java客户端发送数据之后还并未清空的原由。真表示马虎。DataOutputStream.flush();

 

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注