拆解游戏开发中策划配置动态公式问题

星期一, 2015-04-13 | Author: Lee | JAVA-and-J2EE, 游戏开发 | 没有评论

游戏开发中,策划总希望自己能配置奖励等公式,从程序这边对于这种太动态的东西是有点不太想去实现添加它;

既然有需求也要实现,从spring里剥离的SpelExpressionParser 可以很好的解决这个问题, 支持常见的 +—X/(加减乘除) 和指数计算^等

依赖 spring-expression-3.2.8.RELEASE.jar, 运行还需要 核心库 spring-core-3.2.8.RELEASE.jar
上代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.i5a6.semp.test;
 
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
 
public class TestExpress {
 
	public static void main(String[] args) {
		int num = dynamicCalOutput(2, 2, "#playerLevel^(1/2.7)*100*#num");
 
		System.out.println((Math.pow(2, (1 / 2.7)) * 100));
		System.out.println(num);
 
	}
 
	public static int dynamicCalOutput(int lev, int num, String arithmetic) {
		if (arithmetic == null || arithmetic.length() <= 0) {
			return 0;
		}
		ExpressionParser parser = new SpelExpressionParser();
		Expression expression = parser.parseExpression(arithmetic);
 
		EvaluationContext context = new StandardEvaluationContext();
		context.setVariable("playerLevel", lev);
		context.setVariable("num", num);
		return expression.getValue(context, Integer.class);
	}
}

Tags: , ,

一个类说明Java 信号量 Semaphore 的用法

星期五, 2015-04-10 | Author: Lee | JAVA-and-J2EE | 没有评论

在用Semaphore 信号量的时候,感觉对公平调度比较有用,可以控制多线程争夺资源时候,最大可以几个在执行,随手写了代码测试下,如下:
说明: 1. acquire() 获取一个许可,如果没有就等待
2. release() 释放一个许可
3. Semaphore可以控制某个资源可被同时访问的个数,自行初始化的数量,为1当然就顺序执行了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.i5a6.semp.test;
 
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
 
public class SemaphoreTest {
 
	private Semaphore semp;
 
	private ExecutorService executorPool;
 
	public SemaphoreTest(int threadNum) {
		semp = new Semaphore(threadNum);
		executorPool = Executors.newFixedThreadPool(threadNum);
	}
 
	public void doEnd() {
		this.executorPool.shutdown();
	}
 
	public void doMsg(int num) {
		try {
			semp.acquire();
			executorPool.execute(new HelloUExecutor(num));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
 
	class HelloUExecutor implements Runnable {
		private int num;
 
		public HelloUExecutor(int num) {
			this.num = num;
		}
 
		Random r = new Random();
 
		@Override
		public void run() {
			try {
				System.out.println(num);
				Thread.sleep(r.nextInt(1000));
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				semp.release();
			}
		}
	}
 
	public static void main(String[] args) {
		// 初始化为1 顺序执行
		SemaphoreTest st = new SemaphoreTest(5);
		for (int i = 0; i < 20; i++) {
			st.doMsg(i);
		}
		st.doEnd();
	}
 
}

Tags: ,

解决:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart

星期二, 2015-04-07 | Author: Lee | JAVA-and-J2EE | 没有评论

装了apache-maven-3.2.3-bin 并做好配置,在eclipse中新建maven工程时报错:

Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.
Could not resolve artifact
Missing org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE

解决办法:在本地库中装载maven-archetype-quickstart

1.从http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/
或者国内的镜像

http://maven.oschina.net/content/groups/public/org/apache/maven/archetypes/maven-archetype-quickstart/

下载最新版maven-archetype-quickstart-1.1.jar

2.cmd窗口执行mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar -Dfile=maven-archetype-quickstart-1.1.jar

即可

Tags: ,

Mac下启动和停止Mysql及查看端口

星期三, 2015-03-18 | Author: Lee | JAVA-and-J2EE, mac | 没有评论

启动Mysql服务

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

停止Mysql服务

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

重启Mysql服务

sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart

查看是否启动成功可以输入:netstat -an -p tcp 看到3306端口启动成功
//—————————————————————
打开终端,输入:
vim ~/.bash_profile
输入 i
然后粘贴以下内容

# mysql
alias mysql=’/usr/local/mysql/bin/mysql’
alias mysqladmin=’/usr/local/mysql/bin/mysqladmin’
# ls
alias ls=’ls -G’

按ESC键
输入 :x
重新启动终端程序

在终端中 直接输入 mysql 就可以进入mysql

Tags: ,

http协议的手游通信安全构想

星期一, 2015-02-16 | Author: Lee | JAVA-and-J2EE, linux, 游戏开发 | 没有评论

手游中使用http协议,很容易被劫包,获取对应的api接口地址和参数信息,用于篡改数据等制作脱机外挂等.

提升安全必须要做的事情,记忆下一个初步的构想方案.

1. api+key+时间戳+随机key(按照一定算法得出),MD5后生成摘要
2. 如果抓包拿到封装后的地址,照样可以封包访问,所以需要在服务端做限制,对于同一个请求只有第一次访问是有效的
3. 为了前端的反编译安全性,封装成.so包进行调用(提升破解门槛)

对只提供手机api的手机后台服务应用也适用

Tags: ,

Navicat 导出mysql数据库的时候出现 “Cannot proceed because system tables used by Event Scheduler

星期六, 2015-02-14 | Author: Lee | linux, php | 没有评论

用navicat 遭遇 “Cannot proceed because system tables used by Event Scheduler were found damaged at server start” .

使用的APMServ MySQL的集成环境(工具是好用但是找对应的文件是有点麻烦,我还是比较喜欢独立安装各个的支持,追求效率的话可以忽略)

在网上找了下要用什么upgrade什么exe升级下即可,没有找到对应的执行文件,在网上找到一个对应的执行sql即可的方法,如下:

进入mysql的系统库,执行sql:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
DROP TABLE IF EXISTS `event`;
CREATE TABLE `event` (
  `db` CHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
  `name` CHAR(64) NOT NULL DEFAULT '',
  `body` longblob NOT NULL,
  `definer` CHAR(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
  `execute_at` datetime DEFAULT NULL,
  `interval_value` INT(11) DEFAULT NULL,
  `interval_field` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') DEFAULT NULL,
  `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
  `last_executed` datetime DEFAULT NULL,
  `starts` datetime DEFAULT NULL,
  `ends` datetime DEFAULT NULL,
  `status` enum('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL DEFAULT 'ENABLED',
  `on_completion` enum('DROP','PRESERVE') NOT NULL DEFAULT 'DROP',
  `sql_mode` SET('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') NOT NULL DEFAULT '',
  `comment` CHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
  `originator` INT(10) UNSIGNED NOT NULL,
  `time_zone` CHAR(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM',
  `character_set_client` CHAR(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `collation_connection` CHAR(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `db_collation` CHAR(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `body_utf8` longblob,
  PRIMARY KEY (`db`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Events';

Tags: ,

WP-Syntax代码高亮插件的美化和难选中修复

星期三, 2015-01-14 | Author: Lee | html5, pagemaker, wordpress | 没有评论

上次发了一个服务器安装的配置脚本信息,由于脚本比较多,发现浏览的时候用鼠标很难选择一直不知道是什么原因;

期间尝试了去除ad广告部分和统计的js代码,可是问题依旧,无意间更换了wp-syntax的css文件竟然解决了此问题;

也不太想深究其中原因,只把美化后的css代码贴出:
这一段代码替换wp-syntax/css/wp-syntax.css里的内容即可
› Continue reading

Tags: ,

Nginx 1.6.2 + PHP 5.5.20 + MySQL 5.6.10 在 CentOS64 下的编译安装

星期二, 2015-01-06 | Author: Lee | linux | 没有评论

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
1.系统预先配置
yum install wget
yum install pcre
yum install openssl*
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make
yum -y install gd gd2 gd-devel gd2-devel
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
ulimit -SHn 65535
mkdir -p /ia/data/
cd /ia/data/
wget http://ftp.exim.llorien.org/pcre/pcre-8.32.tar.gz
tar -zxvf pcre-8.32.tar.gz 
mkdir tgz
mv pcre-8.32* tgz/
mkdir installsoft
cd installsoft/
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar xzvf nginx-1.6.2.tar.gz 
cd nginx-1.6.2
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/ia/data/tgz/pcre-8.32 --with-http_realip_module --with-http_image_filter_module
make
make install
/usr/local/webserver/nginx/sbin/nginx -V
 
 2、安装 MySQL:
wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.10-linux-glibc2.5-x86_64 /usr/local/webserver/mysql
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p /Data/data/mysql/data
yum install libaio
/usr/local/webserver/mysql/scripts/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/ia/data/mysql/data --user=mysql
 
sed -i "s#/usr/local/mysql#/usr/local/webserver/mysql#g" /usr/local/webserver/mysql/bin/mysqld_safe
GRANT ALL PRIVILEGES ON *.* TO 'ia_admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'ia_admin'@'127.0.0.1' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'ia_admin'@'%' IDENTIFIED BY '12345678';
 
3、安装PHP依赖库
mkdir -p /usr/local/webserver/libs/
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz     
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9/
./configure --prefix=/usr/local/webserver/libs --enable-shared --enable-static --prefix=/usr/local/webserver/libs
make
make install
cd ../
 
wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
tar zxvf libpng-1.6.2.tar.gz
cd libpng-1.6.2/
./configure --prefix=/usr/local/webserver/libs
make
make install
cd ../
 
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
tar zxvf freetype-2.4.12.tar.gz
cd freetype-2.4.12/
./configure --prefix=/usr/local/webserver/libs
make
make install
cd ../
 
 
wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz"
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz"
 
 
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure --prefix=/usr/local/webserver/libs
make
make install
cd libltdl/
./configure --prefix=/usr/local/webserver/libs --enable-ltdl-install
make
make install
cd ../../
 
 
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure --prefix=/usr/local/webserver/libs
make
make install
cd ../
 
vi /etc/ld.so.conf
 
添加:
/usr/local/webserver/libs/lib
 
然后:
ldconfig
 
 
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
export LDFLAGS="-L/usr/local/webserver/libs/lib -L/usr/lib"
export CFLAGS="-I/usr/local/webserver/libs/include -I/usr/include"
touch malloc.h
./configure --prefix=/usr/local/webserver/libs --with-libmcrypt-prefix=/usr/local/webserver/libs
make
make install
cd ../
 
4、编译安装PHP 5.5
wget http://cl1.php.net/get/php-5.5.20.tar.gz/from/this/mirror
tar zxvf php-5.5.20.tar.gz
cd php-5.5.20/
export LIBS="-lm -ltermcap -lresolv"
export DYLD_LIBRARY_PATH="/usr/local/webserver/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
export LD_LIBRARY_PATH="/usr/local/webserver/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/usr/local/webserver/libs --with-jpeg-dir=/usr/local/webserver/libs --with-png-dir=/usr/local/webserver/libs --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/usr/local/webserver/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts
 
make
make install
cp php.ini-development /usr/local/webserver/php/etc/php.ini
cd ../
ln -s /usr/local/webserver/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
mv /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf
 
 5、编译安装PHP扩展
wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-2.69/
./configure --prefix=/usr/local/webserver/libs
make
make install
cd ../
 
wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/
export PHP_AUTOCONF="/usr/local/webserver/libs/bin/autoconf"
export PHP_AUTOHEADER="/usr/local/webserver/libs/bin/autoheader"
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
 
 
  打开 /usr/local/webserver/php/etc/php.ini 查找 ; extension_dir = "ext"
  在其后增加一行:
extension = "memcache.so"

Tags: , , ,

写在新年的致词

星期六, 2015-01-03 | Author: Lee | 体味生活 | 2条评论

又一年的钟声已经敲响,回望2014年的踪迹:页游和手游的初进

1.页游:<烽火连城> 关于大秦帝国的ARPG的网页游戏的上线,一路的辛苦研发运营

2.手游:接收原版基于u3d+c 的射击类休闲的改版和调整,待上线

3.手游:自主研发 卡牌类游戏 u3d+java 进行中

在游戏行业有6年的摸爬滚打,一切努力,尽工作之事.

番外:

1.GTD 任务+工单 记录待处理的事情的记录和跟进系统的 开发(为克服自己的拖延和事情的遗忘而作的系统开发)

2.想法太多,行动太少,(果然是年龄大了,有想法了,发现专注力太差,不太想动,为了以后不后悔要立即行动,新年新动作,努力自己)

flash流媒体视频合成(F4M格式)

星期一, 2014-12-15 | Author: Lee | computer, flash | 没有评论

朋友发过来一个视频希望录制和下载下载,找了下工具借助此工具成功下载和合成;

去缓存拿到对应的流媒体的url地址,可以下载下来也可以通过url的方式进行合成;

推荐下载指定码率的 流媒体文件再进行合成,缓存中直接拿到的可能码率不同,合成的文件无法播放等,谨记.

项目地址:https://github.com/K-S-V/Scripts

本地下载:AdobeHDS.php And Scripts-master

Usage:

php AdobeHDS.php --manifest "your_manifest_url" --delete

MyVideo-Seg1-Frag1.f4f, MyVideo-Seg1-Frag2.f4f………MyVideo-Seg1-Frag99.f4f

php AdobeHDS.php MyVideo-Seg1-Frag

You can use script with following switches:

 --help              displays this help
 --debug             show debug output
 --delete            delete fragments after processing
 --fproxy            force proxy for downloading of fragments
 --play              dump stream to stdout for piping to media player
 --rename            rename fragments sequentially before processing
 --update            update the script to current git version
 --auth      [param] authentication string for fragment requests
 --duration  [param] stop recording after specified number of seconds
 --filesize  [param] split output file in chunks of specified size (MB)
 --fragments [param] base filename for fragments
 --manifest  [param] manifest file for downloading of fragments
 --outdir    [param] destination folder for output file
 --outfile   [param] filename to use for output file
 --parallel  [param] number of fragments to download simultaneously
 --proxy     [param] proxy for downloading of manifest
 --quality   [param] selected quality level (low|medium|high) or exact bitrate
 --referrer  [param] Referer to use for emulation of browser requests
 --start     [param] start from specified fragment
 --useragent [param] User-Agent to use for emulation of browser requests

Tags: ,

Rss

Search

文章分类

Meta